How to get the file name?

#1

I am sending file to CFW and cfw will send it to S3.
So

    let data = new FormData();
    data.append("somekey", "somevalue");
    data.append("image", document.getElementById("image").files[0]);
    axios
        .put("https://domain.xyz/api" , data, config) //domain.xyz/api is my worker route.

In my workers I want to retrieve the file name and send it to s3 like this

    var spacesEndpoint = new AWS.Endpoint("xyz.digitaloceanspaces.com");
    var s3 = new AWS.S3({
      endpoint: spacesEndpoint,
      accessKeyId: accessKeyId,
      secretAccessKey: secretAccessKey,
      params: { Bucket: "xyz" }
    });

    const postData = await r.formData(); //r = request

    var file = postData.get("image");
    var fileName =postData.get("image").name;
    let type =postData.get("image").type ;

    s3.upload(
      {
        Key: fileName,
        Body: file,
        ACL: "public-read",
        ContentType: type
      },
      function(err, data) {
        if (err) {
        }
      }
    );

it’s not working how can I do it?
Thanks.

#2

Hi @sony.sadi,

Our FormData implementation does not currently handle file uploads correctly – it treats them as text. We’d like to add this functionality, but need to be careful not to break any existing scripts which don’t account for file uploads. Unfortunately, this means that it’s going to take a while before we can add the functionality.

Harris