Amplify JS API Documentation
    Preparing search index...
    • Upload data to the specified S3 object path. By default uses a single PUT operation to upload when the payload is less than 5MB. Otherwise, uses multipart upload to upload the payload.

      Server-side uploadData is intended for use in SSR contexts such as Next.js Route Handlers and Server Actions.

      Parameters

      Returns UploadDataServerWithPathOutput

      An UploadDataServerWithPathOutput task. Await the result promise to get the upload result.

      S3Exception when the underlying S3 service returned error.

      StorageValidationErrorCode when API call parameters are invalid.

      // In a Next.js Route Handler
      import { runWithAmplifyServerContext } from '@aws-amplify/adapter-nextjs';
      import { uploadData } from 'aws-amplify/storage/server';
      import { cookies } from 'next/headers';

      export async function POST(request: Request) {
      const formData = await request.formData();
      const file = formData.get('file') as File;
      const result = await runWithAmplifyServerContext({
      nextServerContext: { cookies },
      operation: (contextSpec) =>
      uploadData(contextSpec, { path: `uploads/${file.name}`, data: file }).result,
      });
      return Response.json(result);
      }
    • Parameters

      Returns UploadDataServerOutput

      An UploadDataServerOutput task. Await the result promise to get the upload result.

      The key and accessLevel parameters are deprecated and may be removed in the next major version. Please use path instead.

      Upload data to the specified S3 object key. By default uses a single PUT operation to upload when the payload is less than 5MB. Otherwise, uses multipart upload to upload the payload.

      S3Exception when the underlying S3 service returned error.

      StorageValidationErrorCode when API call parameters are invalid.