Uploading to Google cloud storage using Signed URL and dropzone ( Vuejs )












1














I am able to upload to Google cloud storage directly using the below form submission ( after getting signed URL using Nodejs )



<form action="https://<%=fields.bucket%>.storage.googleapis.com" method="post" enctype="multipart/form-data">
<input type="hidden" name="key" value="<%=fields.key%>">
<input type="hidden" name="bucket" value="<%=fields.bucket%>">
<input type="hidden" name="GoogleAccessId" value="<%=fields.GoogleAccessId%>">
<input type="hidden" name="policy" value="<%=fields.policy%>">
<input type="hidden" name="signature" value="<%=fields.signature%>">
<input type="hidden" name="Content-Type" value="<%=fields['Content-Type']%>">

<input name="file" type="file">
<input type="submit" onclick="myFunction(event)" value="Upload">
</form>


But when using dropzone using the below approach I am getting 400 error . I got my Signed URL successfully and no issues with it . The issue is with axios post method .



 uploadOptions: {
url: "/",
uploadMultiple: false,
method: "PUT",
parallelUploads: 1,
headers: {
"Content-Type": "multipart/form-data"
},
autoProcessQueue: false,
autoDiscover: false,
acceptedFiles: "image/*",
maxFilesize: 5,
maxFiles: 10,
clickable: "#upload",
addRemoveLinks: true,
preventDuplicates: true,
dictDuplicateFile: "Duplicate Files Cannot Be Uploaded",
previewsContainer: ".dropzone-previews",
dictDefaultMessage: "",
thumbnailWidth: 200,
accept: function(file, done) {
var self = this;


var FileSize = file.size;
console.log(" In accept");

k1Object.$axios
.$get("my-board?operation=fileUpload&name=" + file.name)
.then(function(gcmData) {
let postData = gcmData[1];
let actionURL =
"https://" + postData.bucket + ".storage.googleapis.com";
file.uploadURL = actionURL;
k1Object.k1FormData = gcmData[1];
done();
setTimeout(function() {
self.processFile(file);
}, 0)
});


},
init: function() {
var self = this;
this.on("processing", function(file) {
self.options.url = file.uploadURL;
console.log("processing");
});
this.on("sending", function(file, xhr, formData) {
console.log(k1Object.k1FormData.key)
formData.append("key", k1Object.k1FormData.key);
formData.append("bucket", k1Object.k1FormData.bucket);
formData.append("GoogleAccessId", k1Object.k1FormData.GoogleAccessId);
formData.append("policy", k1Object.k1FormData.policy);
formData.append("signature", k1Object.k1FormData.signature);
formData.append("Content-Type", k1Object.k1FormData["Content-Type"]);

var _send = xhr.send;
xhr.send = function() {
_send.call(xhr, file);
};
});
}
}


400 error



<?xml version='1.0' encoding='UTF-8'?><Error><Code>MissingSecurityHeader</Code><Message>Your request was missing a required header.</Message><Details>Authorization</Details></Error>


I am not sure what fields it is expecting , I did even setup CORS rules for my bucket . Thank You .










share|improve this question
























  • Hi Bujji, What does GCM represent in this case is it Google Cloud Messaging? Also could you show the code you're using in the smallest reproducible snippet? Thank you!
    – Frank Natividad
    Nov 16 '18 at 1:01












  • Thank you @FrankNatividad . I am sorry not sure why I wrote GCM , It is GCS ( Google cloud storage ) . I am posting my axios code above
    – Bujji
    Nov 16 '18 at 9:57












  • Thanks @MatrixTai for your comment . I am using XML API and PKCS12 format file . I read somewhere JSON API doesn't support signedURL . Please correct me if I am wrong
    – Bujji
    Nov 16 '18 at 12:00










  • @MatrixTai I am totally confused now looking at the documentation . Looks like I have to follow different approach using JWT token . But not sure how to proceed .. Do we have any full example client ( in my case the user who is using my website ) requesting for JWT token through Nodejs for uploading files and using it to upload the files to GCS ..?
    – Bujji
    Nov 16 '18 at 17:10












  • You're using the XML API Bujji, I want to clarify that. Bujji you're correct that the JSON API does not support signed URLs. Reviewing the code. Thank you!
    – Frank Natividad
    Nov 16 '18 at 22:06
















1














I am able to upload to Google cloud storage directly using the below form submission ( after getting signed URL using Nodejs )



<form action="https://<%=fields.bucket%>.storage.googleapis.com" method="post" enctype="multipart/form-data">
<input type="hidden" name="key" value="<%=fields.key%>">
<input type="hidden" name="bucket" value="<%=fields.bucket%>">
<input type="hidden" name="GoogleAccessId" value="<%=fields.GoogleAccessId%>">
<input type="hidden" name="policy" value="<%=fields.policy%>">
<input type="hidden" name="signature" value="<%=fields.signature%>">
<input type="hidden" name="Content-Type" value="<%=fields['Content-Type']%>">

<input name="file" type="file">
<input type="submit" onclick="myFunction(event)" value="Upload">
</form>


But when using dropzone using the below approach I am getting 400 error . I got my Signed URL successfully and no issues with it . The issue is with axios post method .



 uploadOptions: {
url: "/",
uploadMultiple: false,
method: "PUT",
parallelUploads: 1,
headers: {
"Content-Type": "multipart/form-data"
},
autoProcessQueue: false,
autoDiscover: false,
acceptedFiles: "image/*",
maxFilesize: 5,
maxFiles: 10,
clickable: "#upload",
addRemoveLinks: true,
preventDuplicates: true,
dictDuplicateFile: "Duplicate Files Cannot Be Uploaded",
previewsContainer: ".dropzone-previews",
dictDefaultMessage: "",
thumbnailWidth: 200,
accept: function(file, done) {
var self = this;


var FileSize = file.size;
console.log(" In accept");

k1Object.$axios
.$get("my-board?operation=fileUpload&name=" + file.name)
.then(function(gcmData) {
let postData = gcmData[1];
let actionURL =
"https://" + postData.bucket + ".storage.googleapis.com";
file.uploadURL = actionURL;
k1Object.k1FormData = gcmData[1];
done();
setTimeout(function() {
self.processFile(file);
}, 0)
});


},
init: function() {
var self = this;
this.on("processing", function(file) {
self.options.url = file.uploadURL;
console.log("processing");
});
this.on("sending", function(file, xhr, formData) {
console.log(k1Object.k1FormData.key)
formData.append("key", k1Object.k1FormData.key);
formData.append("bucket", k1Object.k1FormData.bucket);
formData.append("GoogleAccessId", k1Object.k1FormData.GoogleAccessId);
formData.append("policy", k1Object.k1FormData.policy);
formData.append("signature", k1Object.k1FormData.signature);
formData.append("Content-Type", k1Object.k1FormData["Content-Type"]);

var _send = xhr.send;
xhr.send = function() {
_send.call(xhr, file);
};
});
}
}


400 error



<?xml version='1.0' encoding='UTF-8'?><Error><Code>MissingSecurityHeader</Code><Message>Your request was missing a required header.</Message><Details>Authorization</Details></Error>


I am not sure what fields it is expecting , I did even setup CORS rules for my bucket . Thank You .










share|improve this question
























  • Hi Bujji, What does GCM represent in this case is it Google Cloud Messaging? Also could you show the code you're using in the smallest reproducible snippet? Thank you!
    – Frank Natividad
    Nov 16 '18 at 1:01












  • Thank you @FrankNatividad . I am sorry not sure why I wrote GCM , It is GCS ( Google cloud storage ) . I am posting my axios code above
    – Bujji
    Nov 16 '18 at 9:57












  • Thanks @MatrixTai for your comment . I am using XML API and PKCS12 format file . I read somewhere JSON API doesn't support signedURL . Please correct me if I am wrong
    – Bujji
    Nov 16 '18 at 12:00










  • @MatrixTai I am totally confused now looking at the documentation . Looks like I have to follow different approach using JWT token . But not sure how to proceed .. Do we have any full example client ( in my case the user who is using my website ) requesting for JWT token through Nodejs for uploading files and using it to upload the files to GCS ..?
    – Bujji
    Nov 16 '18 at 17:10












  • You're using the XML API Bujji, I want to clarify that. Bujji you're correct that the JSON API does not support signed URLs. Reviewing the code. Thank you!
    – Frank Natividad
    Nov 16 '18 at 22:06














1












1








1


1





I am able to upload to Google cloud storage directly using the below form submission ( after getting signed URL using Nodejs )



<form action="https://<%=fields.bucket%>.storage.googleapis.com" method="post" enctype="multipart/form-data">
<input type="hidden" name="key" value="<%=fields.key%>">
<input type="hidden" name="bucket" value="<%=fields.bucket%>">
<input type="hidden" name="GoogleAccessId" value="<%=fields.GoogleAccessId%>">
<input type="hidden" name="policy" value="<%=fields.policy%>">
<input type="hidden" name="signature" value="<%=fields.signature%>">
<input type="hidden" name="Content-Type" value="<%=fields['Content-Type']%>">

<input name="file" type="file">
<input type="submit" onclick="myFunction(event)" value="Upload">
</form>


But when using dropzone using the below approach I am getting 400 error . I got my Signed URL successfully and no issues with it . The issue is with axios post method .



 uploadOptions: {
url: "/",
uploadMultiple: false,
method: "PUT",
parallelUploads: 1,
headers: {
"Content-Type": "multipart/form-data"
},
autoProcessQueue: false,
autoDiscover: false,
acceptedFiles: "image/*",
maxFilesize: 5,
maxFiles: 10,
clickable: "#upload",
addRemoveLinks: true,
preventDuplicates: true,
dictDuplicateFile: "Duplicate Files Cannot Be Uploaded",
previewsContainer: ".dropzone-previews",
dictDefaultMessage: "",
thumbnailWidth: 200,
accept: function(file, done) {
var self = this;


var FileSize = file.size;
console.log(" In accept");

k1Object.$axios
.$get("my-board?operation=fileUpload&name=" + file.name)
.then(function(gcmData) {
let postData = gcmData[1];
let actionURL =
"https://" + postData.bucket + ".storage.googleapis.com";
file.uploadURL = actionURL;
k1Object.k1FormData = gcmData[1];
done();
setTimeout(function() {
self.processFile(file);
}, 0)
});


},
init: function() {
var self = this;
this.on("processing", function(file) {
self.options.url = file.uploadURL;
console.log("processing");
});
this.on("sending", function(file, xhr, formData) {
console.log(k1Object.k1FormData.key)
formData.append("key", k1Object.k1FormData.key);
formData.append("bucket", k1Object.k1FormData.bucket);
formData.append("GoogleAccessId", k1Object.k1FormData.GoogleAccessId);
formData.append("policy", k1Object.k1FormData.policy);
formData.append("signature", k1Object.k1FormData.signature);
formData.append("Content-Type", k1Object.k1FormData["Content-Type"]);

var _send = xhr.send;
xhr.send = function() {
_send.call(xhr, file);
};
});
}
}


400 error



<?xml version='1.0' encoding='UTF-8'?><Error><Code>MissingSecurityHeader</Code><Message>Your request was missing a required header.</Message><Details>Authorization</Details></Error>


I am not sure what fields it is expecting , I did even setup CORS rules for my bucket . Thank You .










share|improve this question















I am able to upload to Google cloud storage directly using the below form submission ( after getting signed URL using Nodejs )



<form action="https://<%=fields.bucket%>.storage.googleapis.com" method="post" enctype="multipart/form-data">
<input type="hidden" name="key" value="<%=fields.key%>">
<input type="hidden" name="bucket" value="<%=fields.bucket%>">
<input type="hidden" name="GoogleAccessId" value="<%=fields.GoogleAccessId%>">
<input type="hidden" name="policy" value="<%=fields.policy%>">
<input type="hidden" name="signature" value="<%=fields.signature%>">
<input type="hidden" name="Content-Type" value="<%=fields['Content-Type']%>">

<input name="file" type="file">
<input type="submit" onclick="myFunction(event)" value="Upload">
</form>


But when using dropzone using the below approach I am getting 400 error . I got my Signed URL successfully and no issues with it . The issue is with axios post method .



 uploadOptions: {
url: "/",
uploadMultiple: false,
method: "PUT",
parallelUploads: 1,
headers: {
"Content-Type": "multipart/form-data"
},
autoProcessQueue: false,
autoDiscover: false,
acceptedFiles: "image/*",
maxFilesize: 5,
maxFiles: 10,
clickable: "#upload",
addRemoveLinks: true,
preventDuplicates: true,
dictDuplicateFile: "Duplicate Files Cannot Be Uploaded",
previewsContainer: ".dropzone-previews",
dictDefaultMessage: "",
thumbnailWidth: 200,
accept: function(file, done) {
var self = this;


var FileSize = file.size;
console.log(" In accept");

k1Object.$axios
.$get("my-board?operation=fileUpload&name=" + file.name)
.then(function(gcmData) {
let postData = gcmData[1];
let actionURL =
"https://" + postData.bucket + ".storage.googleapis.com";
file.uploadURL = actionURL;
k1Object.k1FormData = gcmData[1];
done();
setTimeout(function() {
self.processFile(file);
}, 0)
});


},
init: function() {
var self = this;
this.on("processing", function(file) {
self.options.url = file.uploadURL;
console.log("processing");
});
this.on("sending", function(file, xhr, formData) {
console.log(k1Object.k1FormData.key)
formData.append("key", k1Object.k1FormData.key);
formData.append("bucket", k1Object.k1FormData.bucket);
formData.append("GoogleAccessId", k1Object.k1FormData.GoogleAccessId);
formData.append("policy", k1Object.k1FormData.policy);
formData.append("signature", k1Object.k1FormData.signature);
formData.append("Content-Type", k1Object.k1FormData["Content-Type"]);

var _send = xhr.send;
xhr.send = function() {
_send.call(xhr, file);
};
});
}
}


400 error



<?xml version='1.0' encoding='UTF-8'?><Error><Code>MissingSecurityHeader</Code><Message>Your request was missing a required header.</Message><Details>Authorization</Details></Error>


I am not sure what fields it is expecting , I did even setup CORS rules for my bucket . Thank You .







vue.js google-cloud-storage axios dropzone.js vue-dropzone






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 '18 at 9:43







Bujji

















asked Nov 15 '18 at 17:45









BujjiBujji

90373156




90373156












  • Hi Bujji, What does GCM represent in this case is it Google Cloud Messaging? Also could you show the code you're using in the smallest reproducible snippet? Thank you!
    – Frank Natividad
    Nov 16 '18 at 1:01












  • Thank you @FrankNatividad . I am sorry not sure why I wrote GCM , It is GCS ( Google cloud storage ) . I am posting my axios code above
    – Bujji
    Nov 16 '18 at 9:57












  • Thanks @MatrixTai for your comment . I am using XML API and PKCS12 format file . I read somewhere JSON API doesn't support signedURL . Please correct me if I am wrong
    – Bujji
    Nov 16 '18 at 12:00










  • @MatrixTai I am totally confused now looking at the documentation . Looks like I have to follow different approach using JWT token . But not sure how to proceed .. Do we have any full example client ( in my case the user who is using my website ) requesting for JWT token through Nodejs for uploading files and using it to upload the files to GCS ..?
    – Bujji
    Nov 16 '18 at 17:10












  • You're using the XML API Bujji, I want to clarify that. Bujji you're correct that the JSON API does not support signed URLs. Reviewing the code. Thank you!
    – Frank Natividad
    Nov 16 '18 at 22:06


















  • Hi Bujji, What does GCM represent in this case is it Google Cloud Messaging? Also could you show the code you're using in the smallest reproducible snippet? Thank you!
    – Frank Natividad
    Nov 16 '18 at 1:01












  • Thank you @FrankNatividad . I am sorry not sure why I wrote GCM , It is GCS ( Google cloud storage ) . I am posting my axios code above
    – Bujji
    Nov 16 '18 at 9:57












  • Thanks @MatrixTai for your comment . I am using XML API and PKCS12 format file . I read somewhere JSON API doesn't support signedURL . Please correct me if I am wrong
    – Bujji
    Nov 16 '18 at 12:00










  • @MatrixTai I am totally confused now looking at the documentation . Looks like I have to follow different approach using JWT token . But not sure how to proceed .. Do we have any full example client ( in my case the user who is using my website ) requesting for JWT token through Nodejs for uploading files and using it to upload the files to GCS ..?
    – Bujji
    Nov 16 '18 at 17:10












  • You're using the XML API Bujji, I want to clarify that. Bujji you're correct that the JSON API does not support signed URLs. Reviewing the code. Thank you!
    – Frank Natividad
    Nov 16 '18 at 22:06
















Hi Bujji, What does GCM represent in this case is it Google Cloud Messaging? Also could you show the code you're using in the smallest reproducible snippet? Thank you!
– Frank Natividad
Nov 16 '18 at 1:01






Hi Bujji, What does GCM represent in this case is it Google Cloud Messaging? Also could you show the code you're using in the smallest reproducible snippet? Thank you!
– Frank Natividad
Nov 16 '18 at 1:01














Thank you @FrankNatividad . I am sorry not sure why I wrote GCM , It is GCS ( Google cloud storage ) . I am posting my axios code above
– Bujji
Nov 16 '18 at 9:57






Thank you @FrankNatividad . I am sorry not sure why I wrote GCM , It is GCS ( Google cloud storage ) . I am posting my axios code above
– Bujji
Nov 16 '18 at 9:57














Thanks @MatrixTai for your comment . I am using XML API and PKCS12 format file . I read somewhere JSON API doesn't support signedURL . Please correct me if I am wrong
– Bujji
Nov 16 '18 at 12:00




Thanks @MatrixTai for your comment . I am using XML API and PKCS12 format file . I read somewhere JSON API doesn't support signedURL . Please correct me if I am wrong
– Bujji
Nov 16 '18 at 12:00












@MatrixTai I am totally confused now looking at the documentation . Looks like I have to follow different approach using JWT token . But not sure how to proceed .. Do we have any full example client ( in my case the user who is using my website ) requesting for JWT token through Nodejs for uploading files and using it to upload the files to GCS ..?
– Bujji
Nov 16 '18 at 17:10






@MatrixTai I am totally confused now looking at the documentation . Looks like I have to follow different approach using JWT token . But not sure how to proceed .. Do we have any full example client ( in my case the user who is using my website ) requesting for JWT token through Nodejs for uploading files and using it to upload the files to GCS ..?
– Bujji
Nov 16 '18 at 17:10














You're using the XML API Bujji, I want to clarify that. Bujji you're correct that the JSON API does not support signed URLs. Reviewing the code. Thank you!
– Frank Natividad
Nov 16 '18 at 22:06




You're using the XML API Bujji, I want to clarify that. Bujji you're correct that the JSON API does not support signed URLs. Reviewing the code. Thank you!
– Frank Natividad
Nov 16 '18 at 22:06












1 Answer
1






active

oldest

votes


















0














This post helped me to resolve my issue . Basically what was wrong is that my file input was the first child of the form instead of at the end. Please see the below stackoverflow link for full answer .



https://stackoverflow.com/a/17524079/274715 .



I am still not sure why moving the file to the end helped me .






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325196%2fuploading-to-google-cloud-storage-using-signed-url-and-dropzone-vuejs%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    This post helped me to resolve my issue . Basically what was wrong is that my file input was the first child of the form instead of at the end. Please see the below stackoverflow link for full answer .



    https://stackoverflow.com/a/17524079/274715 .



    I am still not sure why moving the file to the end helped me .






    share|improve this answer


























      0














      This post helped me to resolve my issue . Basically what was wrong is that my file input was the first child of the form instead of at the end. Please see the below stackoverflow link for full answer .



      https://stackoverflow.com/a/17524079/274715 .



      I am still not sure why moving the file to the end helped me .






      share|improve this answer
























        0












        0








        0






        This post helped me to resolve my issue . Basically what was wrong is that my file input was the first child of the form instead of at the end. Please see the below stackoverflow link for full answer .



        https://stackoverflow.com/a/17524079/274715 .



        I am still not sure why moving the file to the end helped me .






        share|improve this answer












        This post helped me to resolve my issue . Basically what was wrong is that my file input was the first child of the form instead of at the end. Please see the below stackoverflow link for full answer .



        https://stackoverflow.com/a/17524079/274715 .



        I am still not sure why moving the file to the end helped me .







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 1 at 3:22









        BujjiBujji

        90373156




        90373156






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325196%2fuploading-to-google-cloud-storage-using-signed-url-and-dropzone-vuejs%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)