I am trying to add dropzone.js and I'd like to pass another parameter with file, so I put hidden input in form . I can upload file and can read it in Java part but I can't read type_chooser,
------WebKitFormBoundaryZxF6MCYJpTOLUokN
Content-Disposition: form-data; name="type_chooser"
2
------WebKitFormBoundaryZxF6MCYJpTOLUokN
Content-Disposition: form-data; name="file"; filename="isci.xlsx"
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
So if I write;
request.getParameter("type_chooser");
I get null
How can I get type_chooser ?
Note : I tried ;
dropzone.on("sending,function(file,xhr,data){
data.append("type_chooser","1");
});
This gives same output with hidden field in dropzone form, both of them are sending type_chooser but I can't read it in java
Hi i had same problem after lot of research found this solution, worked for me i am using jQuery dropzone.
$("#dropzone").dropzone({
url: "abcd.php",
dictDefaultMessage: "Drop files here or<br>click to upload...",
params: {'param_1':'xyz','para_2':'aaa'}
});
the params
option is what i found to send additional data with dropzone.
the params
option parametes are received in $_POST
and uploaded file in $_FILE
.
Hope this helps.
You can append data along with the formdata
$("div#dropzone_profile_photo").dropzone({
url: "/file-upload/",
init: function() {
this.on("sending", function(file, xhr, formData){
formData.append("data", "loremipsum");
});
}
});
$("div#dropzone_profile_photo").dropzone({
url: "/test",
init: function() {
this.on("sending", function(file, xhr, formData) {
formData.append("data", "loremipsum");
console.log(formData)
});
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/enyo/dropzone/master/dist/dropzone.js"></script>
<link rel="stylesheet" href="https://rawgit.com/enyo/dropzone/master/dist/dropzone.css">
<div id="dropzone_profile_photo" style="width:400px;height:400px; background-color:blue"></div>
Mine was similar to Sahin Yanlık
var myDropzone = new Dropzone(dropzoneid,
{
url: "/files/post",
acceptedFiles: 'image/*',
paramName: "file", // The name that will be used to transfer the file
maxFilesize: 1, // MB
maxFiles: 1,
init: function () {
// Using a closure.
var _this = this;
// Setup the observer for the button.
$("#clear-dropzone").on("click", function () {
// Using "_this" here, because "this" doesn't point to the dropzone anymore
_this.removeAllFiles();
// If you want to cancel uploads as well, you
// could also call _this.removeAllFiles(true);
});
//this.on("maxfilesexceeded", function (file)
//{
// this.removeFile(file);
//});
START (This is the override to send in additional data)
this.on("sending", function(file, xhr, data) {
data.append("filetype", "avataruploadtype");
});
END
this.on("addedfile", function() {
if (this.files[1] != null) {
this.removeFile(this.files[0]);
}
});
this.on("removedfile", function (file) {
//html manipulation to disable and select certain page stuff
});
this.on("success", function (file) {
//html manipulation to disable and select certain page stuff });
},
accept: function (file, done) {
if (file.name == "justinbieber.jpg") {
done("Naha, you don't."); //just in case!!!!
} else {
//console.log("done!!!");
console.log(done());
}
},
headers: { "avatar": "avatarupload" }, //you might be also to piggyback of the headers in serverside
uploadMultiple: false,
clickable: true,
addRemoveLinks: true,
});
try adding it into your get parameter list like this
<form action="/UnitSummary/UploadFile?param1=value¶m2=value" class="dropzone" enctype="multipart/form-data" id="imgUpload" method="post">
<div class="fallback">
<input name="file" type="file" multiple />
<input type="submit" value="Upload" />
</div>
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With