Home  >  Q&A  >  body text

javascript - After JS uses canvas to compress the image, the blob file generated is uploaded to the background and the originalFilename information of the file cannot be obtained.

Input files[0] can get filename and originalFilename

But after it is compressed, it cannot be retrieved

PHP中文网PHP中文网2710 days ago995

reply all(3)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-19 10:11:51

    After the image is compressed by canvas, all you get is the file itself without any name information. You can add a field and pass the name to the backend when submitting;

    var formdata = new FormData();
    formdata.append('0', blod);
    formdata.append('filename', file.filename);

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-19 10:11:51

    formData.append(name, value);
    formData.append(name, value, filename);

    The formData append method has a third parameter, which is used to set the filename for the blob you construct. The filename parameter has compatibility issues with some Android 4.x devices.

    MDN API

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-19 10:11:51

    You can take a look at the content I summarized about image uploading. I hope it will be useful to you.

    Please click me for the link

    reply
    0
  • Cancelreply