使用带有数据对象的Dropzone JS上传到API

时间:2015-04-02 09:08:34

标签: jquery file-upload multipartform-data dropzone.js form-data

是否可以使用dropzone JS上传到带有API的远程服务器,并在请求中包含数据对象。

以下是我需要发送的请求的例子:

---------------------------acebdf13572468
Content-Disposition: form-data; name="eventData" Content-Type: application/json {
    "Description" : "Some description",  
    "EventStoryIdsDelete" : [  ],  
    "PrivacySettings" : 4,  
    "Title" : "Photo event",  
    "EventStories" : [
    {      
        "Caption" : "Some caption",      
        "EventStoryType" : 2,     
        "TaggedUsers" : [      ],
        "Location" : {        
            "Latitude" : 51.52388,
            "Longitude" : -0.04333177,
            "FullAddress" : "Alderney Road, London, United Kingdom"
        }
    }
    ],
    "Date" : "2015-04-01T13:40:25.1790000"
}
---------------------------acebdf13572468
Content-Disposition: form-data; name="userfile"; filename="1.jpg"
Content-Type: image/jpeg
***image***
---------------------------acebdf13572468

1 个答案:

答案 0 :(得分:4)

你的意思是你想用一些自定义参数发送你的图像,对吧? 如果为true,则可以使用dropzone的函数发送

示例:

var myDropzone = new Dropzone('div#uploadFile', { 
    url: "your_url", // Set the url
});
myDropzone.on('sending', function(file, xhr, formData){
    formData.append('Description', 'Some description');
        ....
});

你可以在这里阅读formData