-
Notifications
You must be signed in to change notification settings - Fork 1.4k
How to upload to S3 after getting the signed Url from the backend? #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @harishankards ,
The signed URL you found documentation page is sample response and that too is generated dynamically using this php script.
As per my understating, You are getting signed url from server endpoint You need to add additional prop <vue-dropzone
:awss3="awss3"
v-on:vdropzone-s3-upload-error="s3UploadError"
v-on:vdropzone-s3-upload-success="s3UploadSuccess">
</vue-dropzone> Add dropzoneOptions: {
url: 'http://localhost:3000/file-upload', // File upload endpoint, not signed url endpoint
thumbnailWidth: 150,
maxFilesize: 0.5,
headers: { 'Authorization': 'Bearer ' + this.token },
addRemoveLinks: true,
dictDefaultMessage: "<i class='fa fa-cloud-upload'></i>UPLOAD ME"
},
awss3: {
signingURL: 'http://localhost:3000/attachments', //Where you will get signed url
headers: {},
params : {},
sendFileToServer : true //If you want to upload file to your server along with s3
} Hope this helps you. |
Hi @vrajroham, Thanks for the response. I tried the same way as you mentioned: dropzoneOptions: {
url: 'http://localhost:3000/attachments',
thumbnailWidth: 150,
maxFilesize: 0.5,
headers: { 'Authorization': 'Bearer ' + this.token },
addRemoveLinks: true,
dictDefaultMessage: "<i class='fa fa-cloud-upload'></i>UPLOAD ME"
},
awss3: {
signingURL: 'http://localhost:3000/attachments', // Where you will get signed url
headers: { 'Authorization': 'Bearer ' + this.token },
params: {},
sendFileToServer: false // If you want to upload file to your server along with s3
} and the my backend server sent this as response: { method: 'PUT',
key: 'images/my_image.jpg',
url: 'https://student-burger.s3.amazonaws.com/images/my_image.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAITZKxxxxHPB7M4UA%2F20180514%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180xxx14T100307Z&X-Amz-Expires=86400&X-Amz-Signature=e07717679ee7xxxxxxxx6b366a9812a53e635f5&X-Amz-SignedHeaders=host' } But, nothing happened in the frontend. So, I checked the console, it is displaying this error Uncaught TypeError: Cannot convert undefined or null to object at Also, I want to send the filename to my backend for signing URL. How do I get those? |
@harishankards I got it. I think you should read the documentation completly.
Your response is in invalid format. Your endpoint should return Your response should be like as below, More info here {
"signature":{
"Content-Type":"",
"acl":"public-read-write",
"success_action_status":"201",
"policy":"abc123",
"X-amz-credential":"AKIAIM3WELV3PLALOYDQ\/20171012\/us-west-2\/s3\/aws4_request",
"X-amz-algorithm":"AWS4-HMAC-SHA256",
"X-amz-date":"20171012T054729Z",
"X-amz-signature":"5227d84360d92ef8al45549805b3746f2f1d6641df8986aamcr939c35513cd7c",
"key":"images/my_image.jpg"
},
"postEndpoint":"\/\/student-burger.s3.amazonaws.com\/images"
}
Already note about this is provided in docs.
|
Hi @vrajroham, Got it. Thanks for the explanation. Now I'm able to solve the previous issue, and got up with another one now. {
"signature": {
"Content-Type":"",
"acl":"public-read-write",
"success_action_status":"201",
"policy":"Policy1xxxxx45161391",
"X-Amz-Algorithm":"AWS4-HMAC-SHA256",
"X-Amz-Credential":"AKxxTZKxxxxxxB7M4UA%2F20180514%2Fus-east-1%2Fs3%2Faws4_request",
"X-Amz-Date":"20180514T130047Z",
"X-Amz-Expires":"86400",
"X-Amz-Signature":"25cadc433cxxxxxxxxbdde29e0ea8ec150134bba753b1e568822696094a8c82c58",
"X-Amz-SignedHeaders":"host",
"key":""
},
"postEndPoint":"//student-burger.s3.amazonaws.com/images"
} The above is the one I'm sending from backend. Now, the error I'm getting is: Not sure, why it is coming. But this error where I'm receiving in the page has the route |
|
This is my dropzoneOptions: {
url: 'http://localhost:3000/attachments',
thumbnailWidth: 150,
maxFilesize: 0.5,
headers: { 'Authorization': 'Bearer ' + this.token },
addRemoveLinks: true,
dictDefaultMessage: "<i class='fa fa-cloud-upload'></i>UPLOAD ME"
} Nope. My files are not getting uploaded to S3. No sign of that post/put request to S3 in networks tab. |
Share your complete component and js code. |
@vrajroham |
@abdulbasith7145 Will check it. |
Sure @vrajroham, Please have a look below. <template>
<vue-dropzone ref="myVueDropzone" :destroyDropzone="false"
@vdropzone-success="vsuccess" @vdropzone-removed-file="vremoved"
id="dropzone" :options="dropzoneOptions"
:awss3="awss3"
v-on:vdropzone-s3-upload-error="s3UploadError"
v-on:vdropzone-s3-upload-success="s3UploadSuccess">
</vue-dropzone>
</template>
<script>
import vue2Dropzone from 'vue2-dropzone'
import 'vue2-dropzone/dist/vue2Dropzone.css'
import { eventBus } from '../../main.js'
export default {
name: 'upload',
components: {
vueDropzone: vue2Dropzone
},
data: function () {
return {
token: this.$ls.get('token'),
dropzoneOptions: {
url: 'http://localhost:3000/attachments',
thumbnailWidth: 150,
maxFilesize: 0.5,
headers: { 'Authorization': 'Bearer ' + this.token },
addRemoveLinks: true,
dictDefaultMessage: "<i class='fa fa-cloud-upload'></i>UPLOAD ME"
},
awss3: {
signingURL: 'http://localhost:3000/attachments/signedUrlPut', // Where you will get signed url
headers: { 'Authorization': 'Bearer ' + this.token },
params: {},
sendFileToServer: false
}
}
},
methods: {
vsuccess (file, response) {
this.$store.state.projectUploadedFile.push({
filename: file.name,
signedUrl: response.url
})
eventBus.$emit('uploadedFile', {
projectUploadedFiles: this.$store.state.projectUploadedFile
})
},
vremoved (file, error, xhr) {
const filename = file.name
const signedUrl = this.$store.state.projectUploadedFile.map(item => {
if (item.filename === filename) {
const index = this.$store.state.projectUploadedFile.indexOf(item)
this.$store.state.projectUploadedFile.splice(index, 1)
return item.signedUrl
}
})
this.$http({
method: 'delete',
url: '/attachments',
data: {
filepath: filepath
},
headers: {
'Authorization': 'Bearer ' + this.token
}
})
.then(function (attachmentDeleted) {
console.log('attachment deleted', attachmentDeleted)
})
.catch(function (attachmentDeleteErr) {
console.log('unable to delete attachment', attachmentDeleteErr)
})
},
s3UploadError () {
console.log('s3UploadError')
},
s3UploadSuccess () {
console.log('s3UploadSuccess')
}
},
created () {
this.$store.state.projectUploadedFile = []
}
}
</script> So, this is my component and I'm importing this component to the other components wherever needed. |
@harishankards Just to test, please do following steps and provide the outcome.
Let me know the outcome. |
Hi @vrajroham,
|
Hi @vrajroham, Just wanted to check whether do I have got any updates. Looking forward |
Hi @vrajroham |
Welcome to the club @WajdiF. If you have got some solution, please let me know. Seems @vrajroham is busy |
Hi @harishankards & @WajdiF Can either of you provide a more detailed error message? For your
And also just a friendly reminder this is an open-source project - we do our best to support users but we do ask for a bit of patience as both @vrajroham & myself have families to care for, full-time jobs, and other various life responsibilities. We maintain this component in our spare time with no financial gain. Anyone is free to dig into the source code to work out what is going on. Thanks, |
@harishankards @WajdiF @abdulbasith7145 I spent much time to replicate your issue, but I'cant! Maybe I need more information, which can be provided as Rowan suggested in the previous comment. I have recorded sample video where, you can see the flow how I'm uploading an image to s3, from this doc page (testing purpose).
It's really very hard to take out time from daily schedule, though we are trying our best. What I suggest to you guys is, any of you can look into the code and find out where it is going wrong. It is really simple to start with, like below.
If anyone can provide more specific error then it will be really helpful. Thanks. |
Hey @rowanwins, Thanks for the detailed explanation and yes I understand bro. Regarding the solution, for me, it doesn't go until Whenever I upload something, in the console it throws: And @vrajroham, I clearly understand and thanks a lot for the video. I also used ngrok and I tried with this page, but this time it throws this error: So, my find is the request is made to So, something fishy is happening there only. Note: I also understand that contribution is needed to the repo. But I'm currently locked down until this month end. I shall contribute once my sprint is over. |
Hi, @rowanwins,@vrajroham Thanks a lot for your help and for this library, i totally understand your lack of time. I will do my best to help solve this issue (if any :) ). I cloned the lib and tested locally, i found a weird behavior : {postEndPoint: "//s3-eu-west-3.amazonaws.com/myBucket", signature: {…}} the following exception is thrown when the postEndPoint is undefined : do you |
Hi can you help me please i using node but y only have URL from S3 AWS SDK in back end but i dont understand how to get in node return "signature" object. Below is the current code in node i have const parametros = { var url = s3.getSignedUrl('putObject', parametros , function (err, url) { Please help me |
how to solve this issue- |
@ShrJoshi28 In the past I've gotten a CORS error because I didn't add a CORS policy to my S3 bucket. I've also gotten that error because I was not using a region-specific URL for my upload to S3. In that case my browser said I had a CORS error even though it was not actually a CORS error but rather a redirect error (something about preflight request couldn't be redirected). If you look closely at the redirect you'll see the browser was redirected to a region-specific URL. If you're not using the us-east-1 (Virginia) region, you need to upload to a region-specific URL. For more info, see "region-specific endpoints" at https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html I created a pull request to ensure Dropzone does this correctly: |
Hi,
In my project, I'm using nodejs for backend API and vue for the frontend. I'm using this vue-dropzone in my project.
So, when a file is successfully uploaded into the frontend, I'm taking the filename and type to the backend to create a signedUrl to upload the files in AWS S3. Please refer to the code below.
and the success function
Now, that I have the signedUrl here, how do I send the file to the S3?
In the example provided by you here, the signedURL seemed to be put in a hardcoded way.
But, I'm doing in a dynamic way. So, how do I achieve that?
Thanks in advance.
The text was updated successfully, but these errors were encountered: