SDKsAndroid
Create a file message from a URL
Use FileElem to create a file message for an uploaded resource.
Construct a file message object using a pre-uploaded remote URL hosted on your own cloud storage or enterprise file management system. The SDK does not re-upload the file, making this suitable for integrations with existing document storage repositories.
Code example
FileElem fileElem = new FileElem();
fileElem.setSourceUrl("https://example.com/files/report.pdf");
fileElem.setFileName("Project_Report.pdf");
fileElem.setFileSize(2048000L);
Message message = OpenIMClient.getInstance().messageManager.createFileMessageByURL(fileElem);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
fileElem | FileElem | Yes | File model object. Must specify the remote download URL sourceUrl, file name fileName, and file size fileSize. |
Return value
Returns the created Message object ready for transmission, with contentType set to MessageType.FILE.
State changes after the call
- Local initialization: Initializes the local
Messagestructure without starting network uploads. - Transmission: Because the file asset is pre-hosted, call Send a message without OSS upload to deliver the message without redundant uploads.
Was this page helpful?