web api 2 image upload with parameters - asp.net-web-api

I'm using web api to support the server side of a mobile app and I need to provide an endpoint that support uploading an image to a user profile.
What's the correct way to do this?
Basically the user json looks like this:
{
"username": "username",
"userId" : "guid",
"userProfileImage" : "image goes here"?
}
I'm using azure blob storage an I am able to upload pictures to it (using multipart/form-data) but I have no idea how to pass the Guid for the userId along with the image to store the relationship in the database.

Related

Best approach to download files from Azure Blob Storage using file urls

What is the best approach for the following requirement: I have files stored in Azure Blob Storage with a Private endpoint. I need to show to the user, a table with a column containing these file URLs in the browser. When a user clicks on the link, it should either open the file in a new tab or download the file.
I could show the URLs and download files using the Power BI report when the Blob Storage has public access. But in my scenario, it's a Private endpoint. I tried appending the SAS token to the URL, and that also worked, but in this case, SAS token is visible in the browser which is not allowed in my case. So this also does not work for my scenario.
Can we achieve this using Power BI or Power Apps or any other tools/api?
Could you please suggest the steps?
Thanks
I tried in my environment and got below results:
If you need download blob through browser with private container, you need Blob URL + SAS token because it provides read and writes to access blobs.
If you are using public container, you can download with Blob URL through browser.
There is no option to call your Blob URL by hiding SAS token.
As workaround, if you need to hide the SAS token from the user and try to access the blob, you can make use of Power Automate connector here:
I have connected to my Azure blob storage with these Power Automate connectors. 1) I have first connected to my Blob URL endpoint> And created a SAS URI with this connector.
The SAS URI is created successfully by the connector, and I have saved the SAS token inside the compose variable for it to be hidden.
Later I call an HTTP trigger to trigger the SAS token and get the Image content as HTTP body in the output.
When I decode the HTTP body content> I get my Blob Image successfully.
You can convert base64 to image you can use this link:
If you want your users to access this Blob, you can further convert this b64 encoded string into Image and save the file in OneDrive, SharePoint for your users to access you can refer this link by eric-cheng.
If you want to Email your users the Blob file, that can also be done by using Outlook, Gmail, etc connectors later.

Get Google Sheet Data using V4 API without OAuth

Using this nodeJS example, I could get the data from a public sheet.
But how do I get the data from a non-public sheet owned by me (my google a/c) ?
Is there some way to send in the username and password as arguments ?
I don't want OAuth way as I want the data to be pulled from the sheet & displayed on a public webpage.
The other option I can think of is to have OAuth2 done once write a script to handle refresh tokens automatically as a cron every hour ?
Since this is a file that you the developer own i would recommend using a service account
If you share the file with the service account it will then have permissions to access it without you needing to go though the oauth2 steps of authorizing your application.
On google cloud console simply create Service account credentials
const {google} = require('googleapis');
const auth = new google.auth.GoogleAuth({
keyFile: '/path/to/your-secret-key.json',
scopes: ['https://www.googleapis.com/auth/spreadsheets'],
});
Then change your auth code slightly. Open the service account key file and look for the service account email address its the only one witha # in it. Share the file with the service account like you would any other user in google drive web app.
Once it has access you shouldn't need to authorize the app again.
I have a video on Google drive API upload file with Nodejs + service account which might help you a bit you just need the authorization code. Everything else you have should work as is.

Show Image from sharepoint list

I'm developing a flutter app where i want to show images from sharepoint. My initial idea was to use Image.Network() using a public link of the photo (but this is not viable, with drive from google no problem).
Can this be done with NetworkImage using credentials?
Thanks in advance!!
If you are trying to access images from google drive which having no public URL then it will result in an error.
What you will have to do is to provide an access token on the account to access them like this.
NetworkImage(imgUrl, headers: {"Authorization": "Bearer ${accessToken}"})

How to ensure user see the images pertaining to him only from private blob Azure Storage?

Some of the user’s images are stored in Azure BLOB which is not publicly accessible. In our scenario we upload the images (user’s images) on private blob which later needs to be shown at the client side(Angular). Moreover the user should only be able to see the images that is related to him and not the images of other users.
We can generate the list of images URLs at server side but when this is passed to client side to render, it would fail naturally being blob not being public.
Now, being all the users who would access the application are internal to the organization, I believe authorization to access the images can be achieved by AAD/SAS. However at the same time, I am fail to understand how would I ensure or apply the security that if wanted user X should not be able to read the images of user Y?
Regarding the issue, you can use the following suggestions to implement it.
Store the User information and his image information (such as the image's azure blob container name, azure blob blob name ) in the database.
When the user wants to access the image, query the database with the user information to get these image,
After getting the image information, use the sdk to create sas token then return the image's blob url with sas token to cliend. Regarding how to create sas token, please refer to here.

How can I get Ad name from Ads API using NPM?

I tried with google ads api npm with the query
SELECT ad_group_ad.ad.name, ad_group_ad.ad.type , ad_group_ad.ad.app_ad.headlines,ad_group_ad.ad.app_engagement_ad.headlines,ad_group_ad.ad.text_ad.headline
FROM
ad_group_ad
Response
{
ad: { resource_name: 'customers/xxxxx/ads/xxxxxx', type: 3 },
resource_name: 'customers/xxxxx/adGroupAds/xxxx~xxxxxx
}
But response not containing ad name.
Ad Id and resource name is there.
How can I get the ad name?
IIRC at least in the Adwords API (the Ads API's predecessor), only image ads have a name.
It might be worthwile to run your query on an account where image ads are present (ad_group_ad.ad.type = IMAGE_AD) and see whether your response contains the ad.name field in that scenario.

Resources