This section will provide you with answers to frequently asked questions (FAQs) or issues regarding the Cloud Storage Platform API.


QUESTION

How do you erase old file data to upload new data in the API?


Scenario

The following cURL command was used:


curl -u matest03@example.com:mypass -H “Content-Range:bytes 
0-61/62” -X PUT -k https://api.example.com/v2/files/9E8278E2-D8E8-11DE-8A41-13F6FCC19141/content –data-binary 
@filedata.bin -v

where “fileData.bin” file contains no data.


The response of this request is “204 (No Content).”


The following cURL command was also used:


curl -u matest03@api.example.com:mypass -H 
“Content-Range:bytes 0-61/62” -X PUT -k https://api.example.com/v2/files/9E8278E2-D8E8-11DE-8A41-13F6FCC19141/content -v

In this case, the response code is the same.


The file data is not erased in either case. The file content was checked using the web interface. File data could be uploaded to a specific content range using the first cURL command, but the file data cannot be erased.


ANSWER

If data length is specified, the data amount specified MUST be sent. In this particular case, 62 bytes of data is being specified, but none is being sent. The web server will wait for the data which never comes then discard the connection since the request does not match the headers.


The API does not respond with a data response when data is uploaded. It is, therefore, operating as expected.


To truncate the file, PUT 0 bytes of data without specifying a content-range header. This should truncate the file to 0 bytes.