How to use upload_chunked_stream correctly?

Options
Olex
Olex Member Posts: 2

I'm trying to upload a unity 3D model file. The file size exceeds the maximum file size allowed for the free plan.

But I thought that using the upload_chunked_stream + chunk_size could help me solve this problem. So I did the following:

async uploadChunkedStream(file: any, options: any): Promise<any> {
        return new Promise((resolve, reject) => { 
            const { buffer, originalname } = file;
            const public_id = `Unity3D/${originalname}`;

            const uploadStream = cloudinary.uploader.upload_chunked_stream(
                {
                    resource_type: 'raw',
                    chunk_size: 6000000, // 6MB
                    public_id,
                },
                (error: Error, result: UploadApiResponse) => {
                    if (result) {
                        resolve(result);
                    } else {
                        reject(error);
                    }
                },
            );

            streamifier.createReadStream(buffer).pipe(uploadStream);
        });
}

but it didn’t, response:

[
    {
        "done": false,
        "bytes": 7944344,
        "kind": "upload",
        "resource_type": "raw",
        "public_id": "Unity3D/model.unity3d"
    }
]

Can upload_chunked_stream really help me with this problem? Or what am I doing wrong?

Best Answer

  • SreeCloudinary
    SreeCloudinary Member, Cloudinary Staff Posts: 26
    Answer ✓
    Options

    Hi Olex,

    Thanks for your response.

    You can find details about chunked upload here:

    https://cloudinary.com/documentation/upload_images#chunked_asset_upload

    In short, say you have a 100MB file and would want to tell our server to upload the file into 5 chunks 20MB * 5. This way network is not overloaded. Typically the chunk upload large is required for any files that are larger than 100 MB.

    Hope this helps, please let me know if you have any further questions.

    Best regards,

    Sree

Answers

  • Wissam
    Wissam Member, Cloudinary Staff Posts: 67
    Options

    Hi there,

    From the few upload calls I checked in the log I saw you are getting this error: "FileTooLarge: File size too large. Got 13944344. Maximum is 10485760."

    It is failing because the file size is bigger than the permissible file size for your account.

    This is the error on upload - FileTooLarge: File size too large. Got 14099296. The maximum is 10485760.

    By default, the maximum file size when uploading to Cloudinary is 10MB for our Free plan and 20MB for paid plans.

    For more information: https://support.cloudinary.com/hc/en-us/articles/202520592-Do-you-have-a-file-size-limit-

    Hope this helps, please let me know if you have any further questions.

    Regards,

    Wissam

  • Olex
    Olex Member Posts: 2
    Options

    Okay, that makes a bit more sense now. thanks.

    but I still have a question, how does the ```upload_chunked_stream``` function work (I didn't find any info in the documentation)? I found it in the cloudinary source code.

    I would be very grateful if you could tell me what problems it can solve and when it is best to use it.