Javascript代码:
$http({
method: 'POST',
url: 'some/path',
headers: { 'Content-Type': false },
transformRequest: function (data) {
var formData = new FormData();
formData.append("file", data);
return formData;
},
data: file
}).
success(function (data, status, headers, config) {
alert("success!");
}).
error(function (data, status, headers, config) {
alert("failed!");
});
服务器代码:
func addImageHandler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
blobs, _, err := blobstore.ParseUpload(r)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
file := blobs["file"]
....
}
我很好地处理了处理程序,但是当我解析上传时,我的 blobs 映射中没有任何文件。有什么明显的我失踪了吗?
谢谢!