亚马逊服务器文件上传,javascript – Hlow实现dropzone.js将文件上传到亚马逊s3服务器?...

对于可能也会跳到这个问题的人,我想分享我的工作场景(无服务器与AWS Lambda).

注意:在我的Vue S3 Dropzone component中可以找到完整的示例,与Dropzone和S3相关的代码实际上与框架无关.

基本上,

>客户端(浏览器)调用AWS Lambda函数以获取要添加的每个文件的预签名上载URL.

>当响应中返回预签名URL时,客户端将立即触发dropzone.processFile.

>当正在处理文件时,相应地更改文件的dropzone.options.url.

>当我正在签署一个PUT上传URL时,我将使用xhr.send函数hijack,否则Dropzone将始终在formData中发送文件,这对于PUT上传是不利的.

最终的客户端代码

// In the `accept` function we request a signed upload URL when a file being accepted

accept (file,done) {

lambda.getSignedURL(file)

.then((url) => {

file.uploadURL = url

done()

// And process each file immediately

setTimeout(() => dropzone.processFile(file))

})

.catch((err) => {

done('Failed to get an S3 signed upload URL',err)

})

}

// Set signed upload URL for each file being processing

dropzone.on('processing',(file) => {

dropzone.options.url = file.uploadURL

})

最终的AWS Lambda代码

var AWS = require('aws-sdk')

var s3 = new AWS.S3();

// Make sure you set this env variable correctly

var bucketName = process.env.AWS_BUCKET_NAME

exports.handler = (event,context) => {

if (!event.hasOwnProperty('contentType')) {

context.fail({ err: 'Missing contentType' })

}

if (!event.hasOwnProperty('filePath')) {

context.fail({ err: 'Missing filePath' })

}

var params = {

Bucket: bucketName,Key: event.filePath,Expires: 3600,ContentType: event.contentType

}

s3.getSignedUrl('putObject',params,(err,url) => {

if (err) {

context.fail({ err })

} else {

context.succeed({ url })

}

})

}

演示

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据代码的提示,可能是 `Sam1` 变量名未定义导致的错误。你需要检查一下代码中是否有定义 `Sam1` 变量的语句。另外,你的代码中有一些语法错误,我进行了一些修改,你可以参考一下: ```matlab fs = 1000; fc = 50; f_stop = 200; dt = 1/fs; t = 0 : dt : 10-dt; df = fs/length(t); f = -fs/2 : df : fs/2-df; s0 = ones(1,40); rand('seed',1234); msg = randi([0,1],100,1); msg1 = msg*ones(1, fs/10); msg2 = reshape(msg1',1, length(t)); sam = (msg2).*cos(2*pi*fc*t); r1 = awgn(sam, 15, 'measured'); y = r1.* cos(2*pi*fc*t); Y = fftshift(fft(y))/fs; n_stop = round(f_stop/df); Hlow = zeros(size(f)); Hlow(abs(f)<=n_stop) = 1; DEM = Y.*Hlow; dem = ifft(ifftshift(DEM))*fs; y1 = reshape(dem,40,100); r00 = s0*y1; j = find(r00>20); decmsg = zeros(1,100); decmsg(j) = 1; decmsg = decmsg.'; decmsg1 = decmsg*ones(1,fs/10); decmsg2 = reshape(decmsg1',1, length(t)); subplot(5,1,1); plot(t,msg2); title('原信号'); axis([0 10 0 1.5]); subplot(5,1,2); plot(t,sam); title('已调信号'); axis([0 10 -1.5 1.5]); subplot(5,1,3); plot(t,r1); title('已调信号awgn'); axis([0 10 -1.5 1.5]); subplot(5,1,4); plot(t,dem); title('解调信号'); axis([0 10 0 1.5]); subplot(5,1,5); plot(t,decmsg2); title('判决信号'); axis([0 10 0 1.5]); ``` 这样,你的代码应该就可以正常运行了。这段代码的功能是:随机生成一个二进制消息,进行二进制振幅移移键控(BASK)调制,添加高斯白噪声,然后进行相干解调,最后进行二进制判决。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值