Upload files

更新时间:
复制 MD 格式

You can upload files for EMAS Serverless directly in the console.

Prerequisites

You must meet the following requirements before you upload files:

  • You have created a service space. For more information, see Create your first service space.

  • You can upload media files, such as images, audio, and video. The format requirements are as follows:

    • Images: .jpg, .jpeg, .png, .gif, .bmp, .wbmp, .webp, .svg, .image

    • Audio: .audio, .au, .mp2, .mp3

    • Video: .3gpp, .mp4, .mpeg, .flv, .avi, .wmv, .mpg, .mpga

    • Documents: .pdf, .xls, .xlsx, .doc, .docx, .ppt, .pptx, .txt

  • The file names meet the following requirements:

    • They must be encoded in UTF-8.

    • They are case-sensitive.

    • Their length must be between 1 and 1,023 bytes.

    • They cannot start with a forward slash (/) or a backslash (\\).

Console operations

  1. Log on to the EMAS console, select Serverless, and then click Enter.

  2. In the navigation pane on the left, select Cloud Storage.

  3. Click New Folder to create a folder.

  4. In the target folder, click Upload File.

  5. On the Upload File page, click Direct Upload or drag your files or folders to the upload area.

    Note

    Do not refresh or close the page while the upload is in progress. This action interrupts the upload task and clears the list.

  6. After the upload is complete, click Details to view the file download URL.

Client calls

The following code provides an example:

// Select and upload an image to get the image URL.
attach() {
  my.chooseImage({
    chooseImage: 1,
    success: res => {
      const path = res.apFilePaths[0];
      const options = {
        filePath: path,
        headers: {
          contentDisposition: 'attachment',
        },
      };
      mpserverless.file.uploadFile(options).then((image) => {
        console.log(image);
        this.setData({
          imageUrl: image.fileUrl,
        });
      }).catch(console.log);
    },
  });
}