Last updated: Dec-11-2024
Cloudinary provides support for uploading media directly from your mobile application to your Cloudinary product environment, without going through your servers first. This method allows for faster uploading and a better user experience. It also reduces load on your servers and reduces the complexity of your applications.
This page covers common usage patterns for React Native image and video upload with Cloudinary.
For details on all available upload functionality, see the Upload guide, and the upload method of the Upload API Reference.
For security reasons, mobile applications shouldn't contain your Cloudinary product environment credentials. You can use a signed upload, but that requires generating an authentication signature on your backend. In most cases, you will probably use unsigned uploads that generally provide all the functionality you need for your mobile application, while restricting upload options that require more security.
Upload method
The upload request is managed by the upload
method, which accepts the file to upload, upload options and a callback.
For example, to upload an image called imageFile.jpg
using the default settings:
The result of the upload API call is an object that provides information about the uploaded image, including the assigned public ID of the image and its URL.
Unsigned upload
Unsigned upload is an option for performing upload without the need to generate a signature on your backend. Unsigned upload options are controlled by an upload preset: to use this feature, you first need to enable unsigned uploading for your Cloudinary product environment from the Upload Presets page of the Console Settings.
An upload preset is used to define which upload options will be applied to media assets that are uploaded unsigned with that preset specified. You can edit the preset at any point in time (or create additional upload presets).
Upload options
You can pass any extra upload parameters you'd want to pass, as part of the upload request. For example, to implement an unsigned upload of an image called imageFile.jpg
using an upload preset called sample_preset
, and add a tag with the value of sample
:
Signed upload
Signed uploads require a signature which needs to be created using your api_secret
. You should never expose your secret in client side code and therefore you need to generate an authentication signature on your backend. React Native signed upload with backend support should be implemented in conjunction with one of Cloudinary's backend frameworks (Java, .NET, etc). The various backend frameworks implement helpers to be used in conjunction with React Native, as well as automatically generate the authentication signature for the upload.
To implement signed uploads using React Native to your Cloudinary product environment you must:
- Provide a signature generated on your backend.
- Include the
apiKey
configuration parameter in your front end React Native configuration.
- Add the signature and timestamp to the upload options.
- Call the
upload
method to upload the file.
For example, to upload an image called imageFile.jpg
, set the publicId to newId
, and sign the upload request: