I do not have much experience with flutter, what I would like to know is if there is any way to download a video of amazon s3 and save the file in the memory of the cell phone, thanks
This is the url of the video "https://s3-us-west-1.amazonaws.com/videos.ecuestre.digital/165-3745-40957-1.mp4"
This is how I downloaded a binary file in flutter :
In your pubspec.yaml, add
path_provider: ^0.2.2
includes :
import 'dart:typed_data';
import 'package:flutter/foundation.dart';
import 'package:path_provider/path_provider.dart';
code :
static var httpClient = new HttpClient();
Future<File> _downloadFile(String url, String filename) async {
var request = await httpClient.getUrl(Uri.parse(url));
var response = await request.close();
var bytes = await consolidateHttpClientResponseBytes(response);
String dir = (await getApplicationDocumentsDirectory()).path;
File file = new File('$dir/$filename');
await file.writeAsBytes(bytes);
return file;
}
The function consolidateHttpClientResponseBytes() comes from the flutter docs :
https://docs.flutter.io/flutter/foundation/consolidateHttpClientResponseBytes.html
Note: Edited to more concise version from Simon Lightfoot
If you are using aws resources you can use the Amplify framework to interact with your environment. This is especially helpful if you need interact with a lot of resources. Check the flutter amplify storage docs
Related
Does Adobe provide an official API to convert PDF file to PPT?
https://www.adobe.com/in/acrobat/online/pdf-to-ppt.html
Note: I am only looking for official APIs.
When using the Node.js SDK for Adobe PDF Services API your code might look like this...
// Create an ExecutionContext using
// credentials and create a new
// operation instance.
const executionContext = PDFServicesSdk.ExecutionContext.create(credentials),
exportPDF = PDFServicesSdk.ExportPDF,
exportPdfOperation = exportPDF.Operation.createNew(exportPDF.SupportedTargetFormats.PPTX);
// Set operation input from a source file
const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/exportPDFInput.pdf');
exportPdfOperation.setInput(input);
// Execute the operation and Save the result to the specified location.
exportPdfOperation.execute(executionContext)
.then(result => result.saveAsFile('output/exportPdfOutput.pptx'))
I hope you are well.
Since just now, I can't publish a tweet with an image using the Twitter API.
The following error: {"errors":[{"code":32, "message": "Could not authenticate you."}]}.
And I can't put my finger on what's wrong.
Here's how I upload the image (media)
import 'package:http/http.dart' as http;
import 'dart:convert' as convert;
Future<void> uploadMedia(
List<List<int>> imagesData, String authorizationHeader) async {
var mediaIds = <String>[];
for (var imageData in imagesData) {
final baseURL =
Uri.parse('https://upload.twitter.com/1.1/media/upload.json');
final header = {Fields.authorization.toLowerCase(): authorizationHeader};
final request = http.MultipartRequest('POST', baseURL);
http.MultipartFile multipartFile = http.MultipartFile.fromBytes(
'media', //the name of media parameter
imageData,
);
request.headers.addAll(header);
request.files.add(multipartFile);
var response = await request.send();
response.stream.transform(convert.utf8.decoder).listen((value) {
print('API RESPONSE : $value');
});
}
}
Twitter api documentation to UPLOAD MEDIA
multi_image_picker documentation to upload image to an API
THANKS
Seems like you're getting an authentication error of 32.
As per Twitter documentation, it would mean that something is either malformed in the request, headers, authorization, or the URI (as defined in their documentation).
Make sure your authentication steps are right, and that you have provided the correct permissions for your access tokens.
Team,
I have a blazor web assembly app, which upload the file and process it later. However , I would like to know the base path of the file from where it it picked in the machine.
My code goes as follows . Does anyone has idea to get the file path such as "C:\myfile.txt".
With the File object, I cannot achieve the full path, I can access only its memory stream.
<h1>FILE UPLAOD </h1>
<InputFile OnChange="HandleSelection" ></InputFile>
#code
{
string status;
async Task HandleSelection(IFileListEntry[] files)
{
var file = files.FirstOrDefault();
if (file != null)
{
// Just load into .NET memory to show it can be done
// Alternatively it could be saved to disk, or parsed in memory, or similar
var ms = new MemoryStream();
await file.Data.CopyToAsync(ms);
Console.WriteLine(ms);
status = $"Finished loading {file.Size} bytes from {file.Name}";
var content = new MultipartFormDataContent
{
{ new ByteArrayContent(ms.GetBuffer()),"\"upload\"", file.Name}
};
await client.PostAsync("upload", content);
}
}
}
Even if you get the fullpath (C:\myfile.txt") file won't load
by default, all browser has a security mechanism that any local disk file won't be loaded into a website until you disable that security for your website
Is it possible to download a file from AWS s3 without AWS cli? In my production server I would need to download a config file which is in S3 bucket.
I was thinking of having Amazon Systems Manger run a script that would download the config (YAML files) from the S3. But we do not want to install AWS cli on the production machines. How can I go about this?
You would need some sort of program to call the Amazon S3 API to retrieve the object. For example, a PowerShell script (using AWS Tools for Windows PowerShell) or a Python script that uses the AWS SDK.
You could alternatively generate an Amazon S3 pre-signed URL, which would allow a private object to be downloaded from Amazon S3 via a normal HTTPS call (eg curl). This can be done easily using the AWS SDK for Python, or you could code it yourself without using libraries (it's a bit more complex).
In all examples above, you would need to provide the script/program with a set of IAM Credentials for authenticating with AWS.
Just adding notes for any C# code lovers to solve problem with .Net
Firstly write(C#) code to download private file as string
public string DownloadPrivateFileS3(string fileKey)
{
string accessKey = "YOURVALUE";
string accessSecret = "YOURVALUE";;
string bucket = "YOURVALUE";;
using (s3Client = new AmazonS3Client(accessKey, accessSecret, "YOURVALUE"))
{
var folderPath = "AppData/Websites/Cases";
var fileTransferUtility = new TransferUtility(s3Client);
Stream stream = fileTransferUtility.OpenStream(bucket, folderPath + "/" + fileKey);
using (var memoryStream = new MemoryStream())
{
stream.CopyTo(memoryStream);
var response = memoryStream.ToArray();
return Convert.ToBase64String(response);
}
return "";
}
}
Second Write JQuery Code to download string as Base64
function downloadPrivateFile() {
$.ajax({url: 'DownloadPrivateFileS3?fileName=' + fileName, success: function(result){
var link = this.document.createElement('a');
link.download = fileName;
link.href = "data:application/octet-stream;base64," + result;
this.document.body.appendChild(link);
link.click();
this.document.body.removeChild(link);
}});
}
Call downloadPrivateFile method from anywhere of HTML/C#/JQuery -
Enjoy Happy Coding and Solutions of Complex Problems
My application (MVC) needs to download, zip and return one or many files from Amazon S3. I am using the .NET SDK and GetObject to receive the files, and want to use DotNetZip to then zip them up and return the generated zip file as a file stream result for the user to download.
Can anyone suggest the most efficient way of doing this, I am seeing OutOfMemory exceptions when downloading large files from S3, they could be up to 1gb in size for example.
My code so far;
using (
var client = AWSClientFactory.CreateAmazonS3Client(
"apikey",
"apisecret",
new AmazonS3Config { RegionEndpoint = RegionEndpoint.EUWest1 })
)
{
foreach (var file in files)
{
var request = new GetObjectRequest { BucketName = "bucketname", Key = file };
using (var response = client.GetObject(request))
{
}
}
}
If I copy the response into a memory stream and add that to the zip, all works ok (on small files), but with large files assume I cannot store the entire thing in memory?