filestack-js icon indicating copy to clipboard operation
filestack-js copied to clipboard

Uploading file from AWS Lambda

Open sanjiv221 opened this issue 3 years ago • 1 comments

I need to upload a file from AWS Lambda using filestack-js module. File will come to lambda as an attachment in request from the client. When I call Lambda from POSTMAN, I get the file in string format. what format should I convert the string to and pass that to client.upload? Language I am using is typescript. I am doing something like below but it gives error when creating Blob. I will try to fix it if filestack will accept the file in the format I am passing

    let blob =  new  Blob([request.body], { type: 'text/plain' });
    console.log("after creating blob")
    let file =  new File([blob], "foo.txt", {type: "text/plain"});
    console.log("after creating file onject")
    const client = filestack.init("Your API Key");
    client.upload(file).then(data =>console.log(data.url)); 

NodeJS version I am using is v14.17.6

sanjiv221 avatar Jul 21 '22 17:07 sanjiv221

Hello, I have been able to upload a text file from AWS lambda using the code:

    const client =  filestack.init("your api key");
    await client.upload("/tmp/test.txt", {}, { filename: 'text.txt' }).then(data =>console.log(data.url));  
   
    but the url that I receive shows the content on the browser instead of downloading the file. Please help.
   
  Should I ask these questions to another forum?

sanjiv221 avatar Jul 22 '22 15:07 sanjiv221