Last updated: Oct-31-2023
Cloudinary provides an API for uploading images, videos, and any other kind of file to the cloud. Files uploaded to Cloudinary are stored safely in the cloud with secure backups and revision history. Cloudinary's APIs allow secure uploading from your servers, directly from your visitors' browsers or mobile applications, or fetched via remote public URLs.
Cloudinary's Go SDK wraps Cloudinary's upload API and simplifies the integration. Methods are available for easily performing image and video uploads to the cloud.
This page covers common usage patterns for Go image and video upload with Cloudinary.
You can upload images, videos, or any other raw file to Cloudinary using Go code. Uploading is done over HTTPS using a secure protocol based on your product environment's
The following method uploads an image to the cloud:
For example, uploading a local image file named 'my_image.jpg':
The file to upload can be specified as a local path, a remote HTTP or HTTPS URL, a whitelisted storage bucket (S3 or Google Storage) URL, a Base64 data URI, or an FTP URL. For details and code examples of uploading using each of these data source types, see Required upload parameters.
You upload videos in exactly the same way as images.
The following example uploads
dog.mp4 to Cloudinary and stores it in a bi-level folder structure with the public ID
dog_closeup. It also performs two eager transformations that resize the video to a square and a small rectangle.
By default, uploading is performed synchronously. Once finished, the uploaded image or video is immediately available for transformation and delivery. An upload call returns a
struct with content similar to the following:
The response includes HTTP and HTTPS URLs for accessing the uploaded media asset as well as additional information regarding the uploaded asset: The Public ID, resource type, width and height, file format, file size in bytes, a signature for verifying the response and more.
Cloudinary's Go library supports uploading files from various sources.
You can upload an asset by specifying a local path of an image file. For example:
If your assets are already publicly available online, you can specify their remote HTTP URLs instead of uploading the actual data. In this case, Cloudinary will fetch the asset from its remote URL for you. This option allows for a much faster migration of your existing assets. Here's an example:
If you have existing assets in an Amazon S3 bucket, you can point Cloudinary to their S3 URLs. Note - this option requires a quick manual setup. Contact us and we'll guide you on how to allow Cloudinary access to your relevant S3 buckets.
The upload samples shown above allow your server-side Go code to upload media assets to Cloudinary. In this flow, if you have a web form that allows your users to upload images or videos, the media file's data is first sent to your server and then uploaded to Cloudinary.
A more efficient and powerful option is to allow your users to upload images and videos in your client-side code directly from the browser to Cloudinary instead of going through your servers. This method allows for faster uploading and a better user experience. It also reduces load from your servers and reduces the complexity of your Go applications.
You can upload files directly from the browser using signed or unsigned calls to the upload endpoint, as shown in these examples: Upload multiple files using a form.