我需要上传一个使用Extjs Ajax调用下载的文件。
以下是我尝试的方法。
Ext.Ajax.request({
url: '/someRemoteCloudRepository', // url of remote cloud repository from which i download file.
method: 'GET',
headers: {
'Content-Type': 'application/octet-stream'
},
success: function(response) { // upon success, i need to upload this file into my server application
var form = Ext.create('Ext.form.Panel', {
items: [{
xtype: 'filefield',
name: 'file_path',
}]
});
form.down('filefield').setValue(response.responseText); // Is this the right way to set the downloaded file content ?
var url = 'uploadFile?id=' + '123';
var params = "size=" + getFileSize(); // how can I get the response data size ?
if (form.isValid()) {
form.submit({
url: url,
params: params,
timeout: 60,
waitMsg: 'Uploading file...',
success: function(formBasic, action) {
Ext.Msg.alert('', 'Upload Failed. Please try again');
},
failure: function(response, opts) {
Ext.Msg.alert('', 'Upload Failed. Please try again');
}
});
}
},
failure: function(response) {
Ext.Msg.alert('Status', 'Failed to download file from remote cloud repo.');
}
});
我可以从远程云服务器下载文件,然后在response.responseText
的{{1}}中看到数据。
然后,我创建一个带有success: function(response)
的简单表单,并使用responseText设置其值并执行表单提交。在检查器工具中,我看到正在发送的多部分请求,但状态仍处于“挂起”状态或请求超时。
从远程源下载后如何上传文件?
我尝试过的方法是否正确?如果不能我怎么做?