Shopee SDK API Reference - v1.11.0
    Preparing search index...

    MediaSpaceManager handles media file uploads (images and videos) to Shopee's media space.

    This manager provides functionality for:

    • Uploading images with different scenes and aspect ratios
    • Multi-part video upload with session management
    • Video transcoding status tracking
    • Video upload cancellation

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    config: ShopeeConfig

    Methods

    • Cancel a video upload session.

      Parameters

      • params: CancelVideoUploadParams

        Parameters for canceling video upload

        Parameters for canceling video upload

        • video_upload_id: string

          The ID of this upload session, returned in init_video_upload

      Returns Promise<CancelVideoUploadResponse>

      Promise indicating cancellation status

      Use this API to cancel an ongoing video upload session if needed. After cancellation, the video_upload_id cannot be used for further operations.

      When the API request fails or returns an error

      • error_invalid_upload_id: Invalid upload_id
      • error_already_completed: Upload already completed
      await sdk.mediaSpace.cancelVideoUpload({
      video_upload_id: 'sg_90ce045e-fd92-4f0b-97a4-eda40546cd9f_000000'
      });
    • Complete the video upload and start the transcoding process when all parts are uploaded successfully.

      Parameters

      • params: CompleteVideoUploadParams

        Parameters for completing video upload

        Parameters for completing video upload

        • part_seq_list: number[]

          All uploaded sequence numbers

        • report_data: ReportData

          Report data for tracking upload performance

        • video_upload_id: string

          The ID of this upload session, returned in init_video_upload

      Returns Promise<CompleteVideoUploadResponse>

      Promise indicating completion status

      Call this API after all video parts have been successfully uploaded. The video will be transcoded and ready for use in item operations once transcoding completes.

      When the API request fails or returns an error

      • error_invalid_upload_id: Invalid upload_id
      • error_already_completed: Upload already completed
      await sdk.mediaSpace.completeVideoUpload({
      video_upload_id: 'sg_90ce045e-fd92-4f0b-97a4-eda40546cd9f_000000',
      part_seq_list: [0, 1, 2, 3],
      report_data: { upload_cost: 11832 }
      });
    • Query the upload status and result of video upload.

      Parameters

      • params: GetVideoUploadResultParams

        Parameters for getting video upload result

        Parameters for getting video upload result

        • [key: string]: string | number | boolean | undefined
        • video_upload_id: string

          The video_upload_id from init_video_upload response

      Returns Promise<GetVideoUploadResultResponse>

      Promise with upload status and video information (if transcoding is complete)

      Possible status values:

      • INITIATED: Waiting for part uploading and/or complete_video_upload call
      • TRANSCODING: Transcoding the video file
      • SUCCEEDED: Transcoding completed, ready for use
      • FAILED: Upload failed, check message field for details
      • CANCELLED: Upload was cancelled

      When the API request fails or returns an error

      • error_invalid_upload_id: Invalid upload_id
      const result = await sdk.mediaSpace.getVideoUploadResult({
      video_upload_id: 'sg_90ce045e-fd92-4f0b-97a4-eda40546cd9f_000000'
      });
      if (result.response.status === 'SUCCEEDED') {
      console.log('Video URL:', result.response.video_info.video_url_list[0].video_url);
      }
    • Initiate video upload session.

      Parameters

      • params: InitVideoUploadParams

        Parameters for initializing video upload

        Parameters for initializing video upload

        • file_md5: string

          MD5 of video file

        • file_size: number

          Size of video file, in bytes. Maximum is 30MB

      Returns Promise<InitVideoUploadResponse>

      Promise with video_upload_id for subsequent upload operations

      Video duration should be between 10s and 60s (inclusive). Use the returned video_upload_id for uploading video parts and completing the upload.

      When the API request fails or returns an error

      • error_file_size: File size is too large. Video size should be less than 30M
      • error_param: Invalid parameter
      const result = await sdk.mediaSpace.initVideoUpload({
      file_md5: '2abf0b6e5ff90ff24437a0808f171a93',
      file_size: 1261876
      });
      const uploadId = result.response.video_upload_id;
    • Upload multiple image files to MediaSpace (less than 9 images).

      Parameters

      • params: UploadImageParams

        Parameters for image upload

        Parameters for uploading image to MediaSpace

        • Optionalimage?: File | Blob | Buffer<ArrayBufferLike>

          Image files. Max 10.0 MB each. Image format accepted: JPG, JPEG, PNG. Image number should be less than 9. Note: This is handled as multipart/form-data in the actual request

        • Optionalratio?: "1:1" | "3:4"

          Image aspect ratio. Only applicable to whitelisted sellers. Supported values: "1:1" (default), "3:4"

        • Optionalscene?: "normal" | "desc"

          The scene where the picture is used. Default is 'normal'

          • normal: Process the image as a square image (recommended for item images)
          • desc: Do not process the image (recommended for extend_description images)

      Returns Promise<UploadImageResponse>

      Promise with uploaded image information including image IDs and URLs

      This API requires multipart/form-data content type.

      • normal scene: Images will be processed as square images (recommended for item images)
      • desc scene: Images will not be processed (recommended for extend_description)

      When the API request fails or returns an error

      • error_tier_img_partial: Internal error, please contact openapi team
      • error_tier_img_old_app: Internal error, please contact openapi team
      const result = await sdk.mediaSpace.uploadImage({
      scene: 'normal',
      ratio: '1:1',
      image: imageFile
      });
      console.log('Uploaded image ID:', result.response.image_info_list[0].image_info.image_id);
    • Upload video file by part using the upload_id from initVideoUpload.

      Parameters

      • params: UploadVideoPartParams

        Parameters for uploading video part

        Parameters for uploading video part

        • content_md5: string

          MD5 of this part

        • Optionalpart_content?: File | Blob | Buffer<ArrayBufferLike>

          The content of this part of file. Part size should be exactly 4MB, except last part of file. Note: This is handled as multipart/form-data in the actual request

        • part_seq: number

          Sequence of the current part, starts from 0

        • video_upload_id: string

          The video_upload_id from init_video_upload response

      Returns Promise<UploadVideoPartResponse>

      Promise indicating success or failure of the part upload

      The request Content-Type should be multipart/form-data. Part size should be exactly 4MB, except for the last part of file.

      When the API request fails or returns an error

      • error_invalid_upload_id: Invalid upload_id
      • error_invalid_part_seq: Invalid part_seq
      • error_invalid_part_size: Invalid part_size
      await sdk.mediaSpace.uploadVideoPart({
      video_upload_id: 'sg_90ce045e-fd92-4f0b-97a4-eda40546cd9f_000000',
      part_seq: 0,
      content_md5: '3bb08579fffbfc13ed9d23cda8bbb46d',
      part_content: videoPart
      });