3
我在尝试从超级用户向Amazon S3执行CORS请求以上传文件时遇到问题。首先,我正在向该策略请求一个node.js服务器。我返回这样一个JSON对象:我如何从摩卡/ superagent测试CORS上传电话到亚马逊-s3?
{
s3PolicyBase64: '',
s3Signature: '',
s3Key: '',
s3ObjectKey: 'ftriana3185/inputData/input_fdc2f7f4b050c5884e5ac60a43bfc0d8ff26d549.csv' }
然后我尝试从superagent使用节点返回的策略上传本地文件。我的代码如下所示:
it('GET /inputFiles/s3Credential', function(done) {
var csvPath = './files/inputFileResource/countrylist.csv';
var request = {};
request.ext = 'csv';
clientAgent.get(localPath + '/inputFiles/s3Credential').send(request).end(function(response) {
var s3PolicyBase64 = response.body.s3PolicyBase64;
var s3Signature = response.body.s3Signature;
var s3Key = response.body.s3Key;
var s3ObjectKey = response.body.s3ObjectKey;
var request = clientAgent.post('bucket-name.s3.amazonaws.com')
.type('form')
.field('key', s3ObjectKey)
.field('AWSAccessKeyId', s3Key)
.field('acl', 'public-read')
.field('policy', s3PolicyBase64)
.field('signature', s3Signature)
.attach('mycsv', csvPath).end(function(response){
console.log(response);
});
});
});
我相信这个问题是在我这样做从SuperAgent的请求,因为我也有一个HTML表单正常工作的形式。那么,为此目的使用superagent的正确形式是什么?