将pdf文件从本地系统上传到aws-s3

时间:2016-06-07 16:16:38

标签: angularjs amazon-web-services pdf amazon-s3 fileapi

在我的无服务器应用中,我需要动态生成pdf,然后将生成的pdf上传到 aws-s3 bucket 。但是在无服务器中,我们只能发送json请求,所以我将我的html字符串发送到无服务器,它生成pdf然后将生成的pdf保存到本地机器中。我想,我可以做的那部分,但我的问题是,我需要将新生成的pdf上传到 aws-s3 。我的代码如下:

角色代码

$scope.generate_pdf = function() {

   var html = angular.element('html').html();

    var service = API.getService();   // sent html string as json for generating  pdf
    service.downloadPdf({}, { html : html },
        function(res) {
           console.log("res : ", res);  // res.url: /tmp/dynamica-generate.pdf
                                      // pdf is saved into '/tmp' folder
                                     // now I want to upload pdf from '/tmp' folder to aws-s3


       }, function(err) {
           console.log("err : ", err);
       });

};

我如何解决这个问题,先谢谢。

2 个答案:

答案 0 :(得分:0)

如果要将文件从本地计算机上传到S3存储桶。在本地计算机上安装AWS Cli。完成后,为此命令添加一个cron作业

aws s3 sync /tmp/* s3://mybucket 

答案 1 :(得分:0)

您应该能够使用aws Javascript S3 sdk将JS代码集成到angularJS代码中。

您可以关注this blog postgithub code

它还提到了使用公共IAM帐户设置凭据。根据您向客户端提供文件的方式,您也可以使用预签名URL进行检查。

相关问题