How can I send a file to AWS S3 using a signed URL with cordova-plugin-file-transfer?

I have successfully uploaded to S3 using a file picker and regular XMLHttpRequest, but I'm struggling to achieve the same with the cordova file transfer plugin.

I suspect that the issue lies in the plugin not generating the correct signable request or having trouble with the local file URI provided. I've experimented with various parameters like headers and URI types, but the documentation isn't very helpful, and the plugin source code is confusing.

The format of the string that the request needs to match is as follows:

PUT

1391784394
x-amz-acl:public-read
/the-app/317fdf654f9e3299f238d97d39f10fb1

Any suggestions or perhaps a functional code snippet?

Answer №1

Although it took me a while, I recently encountered an issue with uploading an image using the javascript version of the AWS SDK to create a presigned URL. In case anyone else is facing similar problems, here's how I managed to solve it.

The key to resolving the problem lies in understanding the StringToSign element that triggers the SignatureDoesNotMatch error from Amazon. In my scenario, the StringToSign looked something like this:

<StringToSign>
    PUT\n\nmultipart/form-data; boundary=+++++org.apache.cordova.formBoundary\n1481366396\n/bucketName/fileName.jpg
</StringToSign>

When generating a presigned URL for S3 upload using the aws-sdk, a string is constructed based on various request elements and hashed using your AWS secret. The resulting signature is appended to the URL as a parameter. If the hashes don't match during the upload request, the SignatureDoesNotMatch error occurs.

To prevent this error, you need to ensure that the string generated by the aws-sdk matches the one created by the server. This can be achieved by modifying the code within the sign method found in

node_modules/aws-sdk/lib/signers/s3.js
.

By adjusting the request headers and content types specified in both the presigned URL generation and the client-side file upload, you can sync the signing strings and successfully upload files to your bucket.

Answer №2

I have encountered some difficulties with this plugin

The most effective way I have discovered to upload a file with a signature is through the method devised by Christophe Coenraets:

By following this approach, you can successfully upload your files using the cordova-plugin-file-transfer

Initially, I attempted to utilize the aws-sdk on my server in conjunction with getSignedUrl()

It would generate the signed link, allowing for seamless uploads. However, when utilizing the plugin, I consistently encountered a 403 error: signatures do not match

This issue might be related to the content length parameter, as I have yet to find a functional solution utilizing aws-sdk alongside the plugin

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

HTML: Determine the Precise Location of a Div Element That is Centered

Imagine I have this image: Is there a way for me to determine the x/y or left/top properties of my canvas if it is centered using the following CSS: #canvas-container { width: 100px; height:100px; margin: 0px auto; } Note ...

Is React Context suitable for use with containers too?

React provides an explanation for the use of Context feature Context in React allows data sharing that can be seen as "global" within a tree of components, like the authenticated user, theme, or language preference. Although this concept works well for ...

Tips for Displaying Label Names in Dashboard Charts

Can anyone provide guidance on displaying category names in a chart? To see the relevant code snippet, check row 92 where categories are fetched from an API and connected to products. I am trying to understand how to retrieve data based on category nam ...

Fetch the video (categoryID) from YouTube by utilizing JSON technology

I am looking to integrate the functionality of uploading YouTube videos from my app and then locating those videos afterwards. To achieve this, I utilized the v3 YouTube API for video uploads. The code snippet below demonstrates how I set the title, descr ...

Which framework should be used: client-side or server-side?

I am working on a project similar to craiglist, where users can post announcements for everyday items like cars and flats. I have already developed a significant portion of the backend using a RESTful API in three-tier architecture with Java, connecting to ...

Converting individual items into an array of objects within a JSON file for export

Currently, I am utilizing node.js and my loop is producing a single object that looks like this: Output { prop1:"val1", prop2:"val2", .. } This object is generated every 10 seconds and it may contain different keys and values each time. To write t ...

What is the best way to allow JavaScript to access a Laravel asset?

Currently, I am working on creating a slideshow and have implemented a navbar.js file with the following code: images[0] = "{{ asset('cover/deanna-j-3GZlhROZIQg-unsplash.jpg')}}"; images[1] = "{{ asset('cover/kevin-laminto ...

Is there a way to retrieve the io object within the io.sockets.on callback function?

My preference is to not alter my sockets method. I was hoping to be able to utilize the io object within the connected function. Could this be a possibility? function sockets (server) { const io = require('socket.io')(server); io.sockets.on ...

How can I access the Gmail app without being taken directly to the message sending screen?

How can I open my Gmail app with a button click without sending a message? Most tutorials show how to send messages using Intent.ACTION_SEND, but I simply want to view my messages list. Should I find the package name and launch the app, or is there a bet ...

What is the process for adding an icon to each item in a listview?

I am working on setting icons for each item in a listview using Java code or XML layout. The listview contains multiple items and I want to assign an icon to each of them. Here is the icon that I am referring to: @Override public void onCreate(Bundle sa ...

I successfully linked expressjs, nodejs, reactjs, and mysql in my project. I'm puzzled as to why everything runs smoothly after I restart my express server, but encounters issues when I refresh the page

express path users.js var express = require('express'); var router = express.Router(); const connection = require('./MySQL.js') /* Accessing user data. */ router.get('/', function(req, res, next) { connection.connect() ...

What is the reason behind Visual Studio intellisense not displaying the methods of XMLHttpRequest objects?

Why am I unable to access the open and send methods of the XMLHttpRequest object in Visual Studio's Intellisense? var httprequest = new XMLHttpRequest(); httprequest. I cannot see the methods in Intellisense after the dot. ...

Utilizing HighCharts Bubble Graph with JSON Data Feed

I am currently facing an issue with my bubble chart series not plotting, even though I followed the HighCharts example tutorial. I am not seeing any errors on the browser console, which is making it challenging for me to troubleshoot. Here is the data I ...

Ensuring precise accuracy in JavaScript; transforming 0.5 into 0.5000

My current challenge involves converting every fraction number to n decimal places in JavaScript/Node.js. However, I've encountered a roadblock as it appears impossible to convert 0.5 to 0.5000. This discrepancy is causing my test cases that anticipat ...

Implementing a pull-to-refresh feature in React Native using Redux

I need to implement pull to refresh functionality, but I'm unsure of what to call from _Refresh(). My actions, constants, and reducers are stored on another page. How can I trigger the API again? Thank you in advance for your assistance. class Homewo ...

jQuery allows you to disable all other checkboxes when a specific one is checked

Whenever the "No" option is selected from a group of radio buttons, a DIV containing 6 checkboxes (with different names/IDs) should be revealed. Likewise, if the "None" option is checked, the other checkboxes should be disabled (and enabled once "None" is ...

"Encountering unexpected empty file creation while attempting to utilize Node.js for creating a bucket and pushing an object

As a newcomer to using ExpressJS (built on Node.js) for uploading content to Amazon S3, I followed the provided example from Amazon. However, upon checking the S3 Management Console, I noticed an additional file with the same name as the bucket I just cr ...

Can I apply a universal babel configuration across all of my personal projects?

It becomes tedious to duplicate the same configuration file for each new project I start. ...

Issue with ISO-8859-1 character encoding in table formatting

I have set my website to use ISO-8859-1 encoding and special characters are displaying correctly. However, I'm facing an issue with the datatables plugin which does not seem to recognize special characters in the table data. Do I need to configure an ...

The Typescript loop appears to be stuck and not moving through the

I have encountered a problem while trying to iterate through my array using foreach and forloop in an angular 8 application. Despite having 250 objects in the array, it is not iterating through any elements. I am unable to figure out what the issue could b ...