## Audio Upload to Cloud

### Feature Introduction

<div style="margin-top: 20px;">
<img alt="Original Video" src="https://images.tuyacn.com/rms-static/f1a55ea0-41b8-11f0-9f57-5d628208d2a7-1749092303242.jpg?tyName=uploud" width="300" style="border: 1px solid #000000">
</div>

1. The audio upload to cloud primarily involves the following steps: obtaining a temporary address upload signature, uploading the audio file, getting upload status, polling large file upload status, and saving pet media files.

2. Audio upload to cloud mainly relies on the following 5 key capabilities:

- **Obtain Temporary Address Upload Signature**  
   Developers can use the [fetchDeviceFileSign](/en/miniapp/develop/ray/api/device-file/upload-file/fetchDeviceFileSign) API to obtain detailed configuration information for the "Moment" service.

- **Upload Audio File**  
   Developers can use the [uploadFile](/en/miniapp/develop/miniapp/api/network/upload/uploadFile) API to upload audio files.

- **Get Upload Status**  
   Developers can use the [fetchDeviceFileUploadState](/en/miniapp/develop/ray/api/device-file/upload-file/fetchDeviceFileUploadState) API to get the upload status.

- **Polling Large File Upload Status**  
   Developers can use the [fetchBigPublicFileUploadState](/en/miniapp/develop/ray/api/device-file/upload-file/fetchBigPublicFileUploadState) API to poll large file upload status.

- **Save Pet Media Files**  
   Developers can use the [fileRelationSave](/en/miniapp/develop/ray/api/ai/aiPet/pet_media-device/fileRelationSave) API to save pet media files.

### Interaction Flow

```mermaid
sequenceDiagram
    participant User
    participant Panel
    participant Cloud

    rect rgb(220, 245, 245)
        Note over User, Cloud: Audio File Upload Process
        User ->> Panel: Completes recording
        Panel ->> Cloud: fetchDeviceFileSign() requests temporary address and signature
        Cloud -->> Panel: Returns temporary address and signature
    end

    rect rgb(245, 245, 220)
        Note over Panel, Cloud: Upload Audio File
        Panel ->> Cloud: uploadFile() uploads the file to the temporary address
        Cloud -->> Panel: Uploading...
    end

    rect rgb(245, 220, 245)
        Note over Panel, Cloud: Query Upload Status
        alt File Size Normal
            Panel ->> Cloud: fetchDeviceFileUploadState()
            Cloud -->> Panel: Returns cloud-stored file information
        else File Too Large (greater than 5M)
            loop Poll to get cloud storage key
                Panel ->> Cloud: fetchBigPublicFileUploadState()
                Cloud -->> Panel: Returns cloud-stored file information
            end
        end
    end

    rect rgb(220, 245, 220)
        Note over Panel, Cloud: Complete Upload Operation
        Panel ->> Cloud: fileRelationSave()
        Cloud -->> Panel: Upload completed, returns cloud-stored file information
    end
```
