Uploading with Nextjs server action + cloudinary SDK

LeoJohn Member Posts: 3

I dont know how to convert file to something else so it can be uploaded though using cloudinary.uploader.upload

async function myAction(formData: FormData) {

    'use server'

    const file = formData.get('getImage')

    formData.forEach((value, key) => {

      if (key === 'getImage') {

          const a = value as File;

    const blob = URL.createObjectURL(a)

    cloudinary.uploader.upload(blob).then((response) => response.json())





  • Tamara
    Tamara Member, Cloudinary Staff Posts: 102

    Hi there, can you please clarify what you are trying to achieve?

    Cloudinary's upload method accepts the following types for the file parameter:

    • A local file path (supported in Cloudinary SDKs only)
    • The actual data (byte array buffer). For example, in some Cloudinary SDKs, this could be an IO input stream of the data (e.g., File.open(file, "rb")).
    • The Data URI (Base64 encoded), max ~60MB (62,910,000 chars)
    • The remote FTP, HTTP or HTTPS URL address of an existing, publicly-accessible file
    • An S3 URL of a whitelisted bucket

    If you're able to access the blob data (not just the blob URL), it can be converted to a data URI which will be accepted by the file parameter to Cloudinary's upload method.