Common SDK Issues
What do I do if I upload a file using a file stream/handle, but the uploaded file is truncated or the size is 0?
If the file is uploaded with a file stream/handle, the stream or handle usually contains an offset pointer. If the stream/handle is used before being uploaded, the offset pointer may not point to the starting point of the file. In this case, the SDK uploads the file starting from where the offset points to by default, resulting in the truncated or 0-size file. To solve this problem, you are advised to check the offset, or point the offset to the file’s starting point manually if necessary.
How do I get the object’s URL after it is successfully uploaded?
The object access address (file URL) in COS uses a fixed format. For more information, please refer to Object Overview > Object Access Address.
What do I do if the system reports that the temporary key expired when I upload files?
Please follow the steps below for troubleshooting:
1. Check whether the time of the machine that runs your applications is correct. If the machine time is incorrect, rectify it.
2. Check whether the expiration time (
expirationDate) that you set is earlier than the current time. The current time being later than the expiration time will cause the signature to expire. In that case, you need to change the expiration time and regenerate a temporary key.3. The iOS SDK initializes using the QCloudSignatureProvider and QCloudCredentailFenceQueueDelegate protocols. The QCloudCredentailFenceQueue scaffold caches and reuses temporary keys. You can update the cache by reinitializing the credentialFenceQueue instance to avoid using expired temporary keys. For detailed guidance, please refer to Creating a COS Service Instance with the iOS SDK.
How do I determine whether files are successfully uploaded?
In COS, each object has a corresponding Etag value. After a successful file upload, a string-type Etag value is returned. If the returned Etag is not NULL, you can add a conditional statement to confirm whether the file has been uploaded successfully.
How do I request an object for which hotlink protection is configured?
Add a Header with a specified referer to your request for an object.
Does generating a pre-signed URL generate network requests and incur fees? Will there be a delay?
Generating a pre-signed URL is local logic and does not generate network requests, causing no additional network latency and no additional cost. You can call the SDK API to generate a pre-signed URL at any time when needed.
How do I configure a custom domain name for a COS pre-signed URL?
A pre-signed URL contains a fixed default domain name, which can be replaced via encoding.
How do I create a directory in COS SDK?
In COS, directories are virtual and are represented by objects ending with a /. To create a directory, call the object upload interface and create an object key ending with a /. For more information, please refer to Mini Program SDK Directory Creation Example.
Why are different results returned when I use the same prefix rule and data structure to obtain ObjectList via COS SDK?
To accommodate user habits, COS simulates the display of "folders" or "directories" in graphical tools such as the console and COSbrowser. This is achieved by creating an object with a key value of "project/" and an empty content, which mimics the appearance of a traditional folder. As a result, the ObjectList obtained through the SDK will include empty objects with object names ending in
/.