在通信部分是否有这种配置的开源示例?
https://github.com/blueimp/jQuery-File-Upload
或者,进一步调查 jquery ajax 调用...
function uploadPicture() {
// blog.w3villa.com/websites/uploading-filesimage-with-ajax-jquery-without-submitting-a-form/
//
var form_data = new FormData(); // Creating object of FormData class
var file_data = photo.src; // Getting the properties of file from file field
// form_data.append("file", file_data); // Appending parameter named file with properties of file_field to form_data
// var blob = new Blob([file_data], {type: 'image/png'});
// form_data.append("file", blob)
var dataURI = photo.src;
alert(dataURI);
form_data.append("file", dataURItoBlob(dataURI));
form_data.append("field1", "stuff1"); // Adding extra parameters to form_data
alert(JSON.stringify(form_data));
$.ajax({
url: serverURL,
dataType: 'json', // the format of the response
cache: false,
contentType: false, // the format of data being sent to the server as part of request
// shazwazza.com/post/Uploading-files-and-JSON-data-in-the-same-request-with-Angular-JS
// setting the Content-type to 'false' will force the request to automatically
// populate the headers properly including the boundary parameter.
// stackoverflow.com/questions/2845459/jquery-how-to-make-post-use-contenttype-application-json
// contentType:"application/json; charset=utf-8",
// contentType:"multipart/form-data; charset=utf-8",
processData: false, // do not convert outgoing data to a string
data: form_data, // Setting the data attribute of ajax with file_data
type: 'post',
success: function(data) {
alert("success! data: " + JSON.stringify(data));
}
});