得到悬浮窗文件上传 [英] Get uploaded file from Dropzone
本文介绍了得到悬浮窗文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Web API方法来上传文件,并返回一个包含文件路径FileResult对象。我怎样才能获得上传的文件的悬浮窗文件路径(如何从网络API方法反应)?
I have a Web API method to upload file and return FileResult object that contains file path. How can I get the file path of uploaded file in dropzone (how to get response from Web API method)?
我的悬浮窗:
module.directive("dzDirective", [
'apiAttachment', function(apiAttachment) {
return {
restrict: "A",
link: function(scope, iElement, iAttrs, controller) {
iElement.dropzone({
url:"/api/1/FileTransfer",
uploadMultiple: false,
init: function() {
var myDropzone = this;
myDropzone.on("complete", function (file) {
DoSomething();
});
}
});
}
};
}
]);
我的Web API方法:
My Web Api method:
[Route("api/1/FileTransfer")]
public async Task<FileResult> Post()
{
if (!Request.Content.IsMimeMultipartContent("form-data"))
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.UnsupportedMediaType));
}
var storageFactory = new StorageFactory();
var streamProvider = new StorageProvider(storageFactory.Create(storage, tempContainer));
await Request.Content.ReadAsMultipartAsync(streamProvider);
return new FileResult
{
FilePaths = streamProvider.Files
};
}
FileResult型号
FileResult Model
public class FileResult
{
public IEnumerable<string> FilePaths { get; set; }
public string Submitter { get; set; }
}
谢谢!
推荐答案
就在这个片段添加到您的悬浮窗初始化
Just add this snippet to your dropzone initializer
Dropzone.options.formUpload = {
init: function() {
this.on("success", function(data) {
var response = $.parseJSON(data.xhr.response);
});
}
}
这篇关于得到悬浮窗文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文