AWS C#lambda文件上传到S3

问题描述 投票:1回答:1

我已经使用Visual Studio空模板为AWS创建了无服务器。我正在尝试向其发送文件,该文件内部使用C#上传到S3。我可以通过控制台应用程序上传文件。我需要以下方面的帮助:一个。如何通过Insomnia或Postman将文件发送到API-现在可以执行此操作b。如何接收文件,以便在我上载S3时能够直接以发送API的方式下载它。-现在就可以进行]

[编辑]C。尝试将文件保存到存储桶时,文件大小小于上传的文件大小,并且已损坏。

代码段:

公共APIGatewayProxyResponse Get(APIGatewayProxyRequest请求,ILambdaContext上下文){        context.Logger.LogLine(Encoding.ASCII.GetByteCount(request.Body).ToString());

        MemoryStream ms = new MemoryStream();


        TransferUtility utility = new TransferUtility(new AmazonS3Client("<AccessKey>", "<SecretKey>", Amazon.RegionEndpoint.USEast1));
        var checker = new TransferUtilityUploadRequest()
        {
            InputStream = new MemoryStream(Encoding.ASCII.GetBytes(request.Body)),
            BucketName = "<BucketName>",
            Key = "<FileName>.pdf"
        };
        utility.Upload(checker);
        var response = new APIGatewayProxyResponse
        {
            StatusCode = (int)HttpStatusCode.OK,
            Body = JsonConvert.SerializeObject(checker),
            Headers = new Dictionary<string, string> { { "Content-Type", "application/json" }, { "Access-Control-Allow-Origin", "*" } }
        };

        return response;
    }

注意:文件可以是docx或pdf。我也有将文件流上传到S3的代码,只需要有关通过APIGatewayProxyRequest类型接收文件并转换为流的信息。

提前感谢。

c# file-io aws-lambda ca-api-gateway
1个回答
0
投票

@@ Parag,尝试使用发布的代码。对我而言,目标文件大小相同,但是内容不可读。

有趣的帖子,请继续更新调查结果。

© www.soinside.com 2019 - 2024. All rights reserved.