dio icon indicating copy to clipboard operation
dio copied to clipboard

Upload file to s3 using presigned url

Open chethanprabhakar opened this issue 6 years ago • 4 comments

Hello,

Need some help on using dio

        "key": signed_url['fields']['key'],
        "AWSAccessKeyId": accessKeyId,
        "policy": policy,
        "signature": signed_url['fields']['signature'],
        "file": await MultipartFile.fromFile(path.dirname(filepath),filename: path.basename(filepath),contentType: new MediaType('application', 'x-tar'))
        
    });
    try {
      var response = await Dio().post('<my bucket>', data: formData);

      print (response.statusCode);
    }catch (e){
      print (e.toString());
    }

I am trying this code to upload a file to s3 using presigned url

I am not seeing any exceptions

What am I doing wrong?

I have also tried http variant as well

Appreciate any pointers. I am falling behind on my deliverables

Thanks

chethanprabhakar avatar Dec 13 '19 17:12 chethanprabhakar

Extending this, I am trying to print the response.

    Dio dio = new Dio();
    var response = await dio.post(_s3Endpoint, data: formData);
    var responseBody = response.data;
    print(responseBody);    

I am not able to get the response data to print. If I put this in a try catch block, I now get a 400 error. I want to get the details of the error.

try{
await Dio().post(_s3Endpoint, data: formData).then((response) {
          if (response.statusCode == 200){
            print("Uploaded!");
          } else {
            print ("**** UNABLE TO UPLOAD ****");
          }
        });
} catch (e) {
  print (e.toString());
}

How do I print the response data?

ctippur avatar Dec 13 '19 19:12 ctippur

Any update on this please?

ctippur avatar Dec 15 '19 06:12 ctippur

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

stale[bot] avatar Jan 14 '20 06:01 stale[bot]

this stackoverflow answer works for me, put it here for someone else has the similar issue.

tsun424 avatar Nov 18 '20 00:11 tsun424