If you are curious about uploading and downloading files in River, follow us on with this document. While working with the API, it is sometimes required to send large files such as a photo, video, or other types of files to the server or even setting a profile picture to the current user.
There are several API methods to save files. It is required to allocate a unique 64-bit client identifier to the file as FileId to send the contents of it.
First of all, the file's binary content is divided into some parts. Except for the last part that its size might be less than PartSize, all other parts must have the same size which indicates by PartSize.
Second, Each part should have a sequence number, FilePart, with a value ranging from 1 to 3000.
Then, to save partitioned files on the server, it is needed to choose a method. The related method is FileSavePart.
After each call, a partition of the data will be saved in a temporary location on the server for future use. Depending on how busy the storage is, this portion of data will be stored for a while and after that, it won't be available.
While saving the file parts by the methods mentioned above, we will face some returned DataInputErrors as follows:
ErrCodeTooMany, ErrItemFileParts: ErrCodeOutOfRange, ErrItemFilePartID: less than 1 and more than 3000 ErrCodeInvalid,ErrItemFilePartSize: The size limit (256 KB) for the content of the file part (chunk) has been exceeded ErrCodeInternal,ErrItemFileParts: It is related to the server errors such as permissions ErrCodeUnavailable, ErrItemFileParts: If face with some problems after putting together the chunks
Besides uploading the parts, in the inputFile constructor, an MD5 hash of the file contents can also be calculated to use as the md5CheckSum parameter.
After receiving the latest chunk, they will put together. When is called a message update, it will save in permanent storage.
The final method might be called and passed the generated inputFile object, after the whole of the file is saved successfully, the inputFile constructor must be passed.
To download the files that have been successfully uploaded on the server, the FileGet method will call which returns the content of a whole file.