Make a S3 resource public read-only for some duration using the AWS SDK for node? - node.js

I have integrated S3 to my node app and upload certain documents on to S3. Need to share these documents with a third party.
Send the URLs to the third party via an API and they will download it immediately. I want to make the S3 objects public for some duration. How do i achieve this ?

S3 presigned URL is what you are looking for, you can use them to generate links for your third party with expiration time. I'm posting the reference links below
Presigned url AWS official documentation
A blog post which demonstrate presigned urls further

With #varnit's help i was able to figure out creating a public URL for certain duration.
I had another issue, get KEY from the resource URL.
Resolved that in Node using this:
AmazonS3URI(resourceUrl)
which returns something like this:
{
"uri":{
"protocol":"https:",
"slashes":true,
"auth":null,
"host":"bucket.s3.region.amazonaws.com",
"port":null,
"hostname":"bucket.s3.region.amazonaws.com",
"hash":null,
"search":null,
"query":null,
"pathname":"/private/region%xxxxxx/file",
"path":"/private/region%xxxxx/file",
"href":"https://bucket.s3.region.amazonaws.com/private/region%xxxxxx/file"
},
"isPathStyle":false,
"bucket":"aaaa-bbbb-ccc",
"key":"private/xxxxx:yyyyy/file",
"region":"region"
}

Related

Add sample image in template header in whatsapp cloud API

I am doing a project using WhatsApp cloud API. I need to create a template with a media header. I have created a template with a media header without a sample image and it gets rejected. So I want to create a template with a sample image in Node JS.
Template with a media header
Add sample image for a template
curl -X POST "https://graph.facebook.com/v14.0/{whatsapp-business-account-ID}/message_templates
?name={template-name}
&language=en_US
&category=TRANSACTIONAL,
&components=[{
type:BODY,
text:{message-text}
},
{
type:HEADER,
format:IMAGE,
example:{header_handle:[{uploaded-image-file-url}]}
}],
&access_token={system-user-access-token}"
I want to add a sample image using Node JS (Not manually like the second picture).
header_handle requires a encrypted file upload provided by facebook.
This can be done by calling 2 apis.
First,
We have to create a session for the file to be uploaded.
For creating session refer this
After creating session, we will get session id to upload the original file to it.Response will look something like this:
{"id":"upload:MTphdHRhY2htZW50Ojlk2mJiZxUwLWV6MDUtNDIwMy05yTA3LWQ4ZDPmZGFkNTM0NT8=?sig=ARZqkGCA_uQMxC8nHKI"}
Second,We have to upload the file to
https://graph.facebook.com/v14.0/{above_id}
This will give a response something similar to
{"h":"2:c2FtcGxlLm1wNA==:image/jpeg:GKAj0gAUCZmJ1voFADip2iIAAAAAbugbAAAA:e:1472075513:ARZ_3ybzrQqEaluMUdI"}
Finally,
{header_handle:["2:c2FtcGxlLm1wNA==:image/jpeg:GKAj0gAUCZmJ1voFADip2iIAAAAAbugbAAAA:e:1472075513:ARZ_3ybzrQqEaluMUdI"]}
Should be added during the request to create template.
It worked for me.
See this for better understanding on how to do it.
The answer Provided by Aravindh is correct, you can follow This document from Meta to upload the Image you want.
Just make sure you use a supported type by WhatsApp API ( For WhatsApp Business Platform Cloud API , For WhatsApp Business Platform On-Premises API ) and the upload end point (file-type — The file's MIME type. Valid values are: image/jpeg, image/jpg, image/png, and video/mp4
)
Double Check if you are following exacly the types supported, for example in case of png, you need to set "file_type" to "image/png" no just "png" when creating the upload session.
I have tested it and it works for me.
Hope this helps

Shopware 6 call api from backend

I am making a new backend page where you should be able to download an export.
I already got the the route and the export working. If I call my export action from curl with sw-access-key I get my download: store-api/v3/_action/orderer-export/77f40024cfd448d9a90063a75dc9fb2e
How do I make the download link with auth?
Update
I added a service and created it like:
vendor/shopware/administration/Resources/app/administration/src/module/sw-import-export/service/importExport.service.js
Also changed store-api to api in my DownloadRoute.php: #RouteScope(scopes={"api"})
Now I can use this new service to call my API and the the file contents as response. Still no download.
Looking at \Shopware\Core\Content\ImportExport\Controller\ImportExportActionController::download I finally got it.
Simply add defaults={"auth_required"=false} to your route:
#Route("/api/v{version}/_action/import-export/file/download", name="api.action.import_export.file.download", defaults={"auth_required"=false}, methods={"GET"})
Security Warning: If your download contains non public information you need to add a secure token or download link. Otherwise your download is free for anyone. Shopwares own ImportExport generates download links with a token. Have a look there.

Can Azure batch transcription results be directed to a non-public url

I would like to use the Microsoft Azure Cognitive Service Speech-to-text. It offers a REST API, which I succesfully have used. I can point to an Azure blob storage using a SAS URI, and the files in the container are transcribed.
My problem is, that when I try to retrieve the transcription results from the API, they are published to a public url. Since voice data can be sensitive, I would like to keep the results stored privately. Is there any way to do this?
I does not seem like it is an option in the API schema, although you can set a destinationContainerUrl. I have tried to set the destinationContainerUrl, but the result does not appear in the container.
I have only used the API reference, which is why I am not posting any code.
You've found the correct option. Using destinationContainerUrl will write the results into this container. Make sure you provide a container SAS which allows listing and writing.
When the job succeeds, the results should be there. Please check that status of your job, maybe it was set to failed.
Documentation about transcriptions:
https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/batch-transcription
If the job succeeds and the files are not on this container, please let us know the $.self link of the job and the creation time, to help us gathering the logs.
Ok. So the solution was super simple. I just did the post request json wrong. destinationContainerUrl needs to be under properties, as shown below:
{"contentUrls": ["LINK-TO-BLOB-SAS-URI-TOKEN"],
"properties": {
"diarizationEnabled": false,
"wordLevelTimestampsEnabled": false,
"punctuationMode": "DictatedAndAutomatic",
"profanityFilterMode": "Masked",
"destinationContainerUrl": "LINK-TO-BLOB-SAS-URI-TOKEN"
},
"locale": "en-US",
"displayName": "Transcription from blob to blob"
}

Download File from OneDrive using REST API

I am trying to find a way out using node js to fetch the list of files (xlsx and CSV files are of my interest) from User's Microsoft OneDrive. From the list, choose the file and then download it into the local system.
I can see Microsoft documentation about using OneDrive REST API here. But, since I am new at this, I am not really able to work this around. Any help will be appreciated.
I want to do something similar to what we can do with Google Drive where I could get a list of files along with their names and unique id and when the user chooses one file, by use of the unique id, I was able to download the required file. I am wondering if a similar thing can be done with OneDrive.
My progress so far:
I am able to ask users to provide their consent and get code in return to redirect Uri (localhost in my case).
The link that does this- https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={my_client_id}&scope=User.Read%20offline_access%20Files.ReadWrite.all%20Files.ReadWrite&response_type=code&response_mode=query&redirect_uri=https://localhost:3400
After getting the code, I exchanged it for refresh token.
To do this exchange, I used Postman for the POST request. The URL for that is https://login.microsoftonline.com/common/oauth2/v2.0/token?grant_type=authorization_code&client_id=your_app_client_id&code=use_the_code_returned_on_previous_step
Now that I have a refresh token, I want to do operations like listing the files on my OneDrive and select anyone to download.
I suggest looking into the Graph API as follows, and using the same auth_token received above. Instead of /me you can substitute a user ID as well.
Get information about the user's drive:
GET https://graph.microsoft.com/v1.0/me/drive
Get the root folder of the drive:
GET https://graph.microsoft.com/v1.0/me/drive/root/
Note: the documentation and the paths in the JSON results say "root:" but I haven't been able to get it work work with the colon.
Embedded in the result you should see:
"folder": {
"childCount": {whatever the count is}
},
To see the files that are in the folder:
GET https://graph.microsoft.com/v1.0/me/drive/root/children
Files will have an id and a name, both of which can be used to retrieve them:
"createdDateTime": "2020-07-05T18:08:37Z",
"eTag": "\"{29C06DFA-92AE-48D5-AF3D-149EF959030F},1\"",
"id": "01EC2X7VP2NXACTLUS2VEK6PIUT34VSAYP",
"lastModifiedDateTime": "2020-07-05T18:08:37Z",
"name": "wizard of wor.png",
To download a file by ID:
https://graph.microsoft.com/v1.0/me/drive/items/01EC2X7VP2NXACTLUS2VEK6PIUT34VSAYP/content
Or by path (in example below Wizard of Wor.png is the file name):
https://graph.microsoft.com/v1.0/me/drive/root/children/Wizard%20of%20Wor.png/content
Documentation sources:
https://learn.microsoft.com/en-us/graph/api/driveitem-list-children?view=graph-rest-1.0&tabs=http
https://learn.microsoft.com/en-us/graph/api/driveitem-get-content?view=graph-rest-1.0&tabs=http

Download and display images from sharepoint (Xamarin.Forms PCL)

I'm currently developping an app based on Sharepoint REST API and Microsoft Graph. My app is composed mainly with a Tabbed Page, and on the first tab I want to display News from sharepoint. To do so I want to get images from the news, but using the url of the images as Image Source returns me "forbidden" error. So, I decided to find a way to download those images. I've been looking for a way for few days now, and found nothing...
Does anyone knows a way to do that, or why do I have a forbidden access error ?
I bring some precisions, I'm using an HttpClient to authenticate to the tenant with REST API :
client = new HttpClient();
Uri mUri = new Uri(App.ReturnUri);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var data = await DependencyService.Get<IAuthenticator>()
.Authenticate(App.LoginAuthority, App.RestResourceUri, App.ClientId, mUri);
App.AuthenticationResult = data;
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", App.AuthenticationResult.AccessToken);
From that, I hope someone knows if there is a way to download images, or to access to url in order to use them as Source. I succeeded in retrieving URLs but not displaying images, knowing that I can retrieve any other data from sharepoint
Thanks for any help,
The Image component can use a URL as its data, but that requires images that aren't behind an authentication which is probably the case with your SharePoint images. That is also why it's returning you a Forbidden error.
var webImage = new Image { Aspect = Aspect.AspectFit };
webImage.Source = ImageSource.FromUri(new Uri("https://xamarin.com/content/images/pages/forms/example-app.png"));
To add the authentication layer for SharePoint you would probably be able to implement your own UriImageSource implementation. In the end an ImageSource only needs a Stream object so getting that from either the internet or local storage would work.
To download and store images you will have to write code for both platforms specifically because local storage works differently. Check out this blog post as a starting point combined with your own piece of code.
https://blog.falafel.com/xamarin-forms-storing-and-retrieving-photos/

Resources