![](/uploads/1/2/6/2/126247002/787306048.png)
What is JotForm?JotForm is a free which helps you create online forms without writing a single line of code. Try Out JotForm!At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.We believe that if one user has a question, there could be more users who may have the same question.
Cloud Storage allows developers to quickly and easily upload files to a Google Cloud Storage bucket provided and managed by Firebase. Since the default Google App Engine app and Firebase share this bucket, configuring public access may make newly uploaded App Engine files publicly accessible as well. By offloading your media files into third party storage locations off your server, you. In Google Drive, you will be creating a folder to upload the private key file.
This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern. Hello Jotform,Is it possible to upload files automatically when submitting a form (i.e. Have a saved file in server or preferred location in a computer)?What I am trying to achieve is to have a file uploaded automatically to google drive so it is already located to the destination folder. At the moment I keep on edtiing a templated document and dragging it manually to the destination folder which is a repetitive task anyway.
At least when it is submitted together with the form I can avoid that mundane task.Any ideas?Kind regards,Genesis.
The Drive API allows you to upload file data when youcreate orupdate aFile resource.
In this guide and reference, media refers to all available files with MIME types that we support for upload to Google Drive. For a list of some of the MIME types that begin with 'application/vnd.google-apps', see create. The user can upload any file they want to Drive and some MIME type will be set for the item. If the format of the content can't be detected, then the MIME type will be set to 'application/octet-stream'.
When you upload media, you use a special URI. Methods that supportmedia uploads have two URI endpoints:
- The
/upload
URI, for the media. The format of the/upload
endpoint is thestandard resource URI with an/upload
prefix. Use this URI when you transferthe media data itself. Example:POST /upload/drive/v3/files
. - The standard resource URI, for the metadata. If the resource contains anydata fields, those fields are used to store metadata that describes the uploadedfile. You can use this URI when you create or update metadata values.Example:
POST /drive/v3/files
.
Upload types
There are three types of uploads you can perform:
- Simple upload:
uploadType=media
. For quick transfer of a small file(5 MB or less). To perform a simple upload, refer toPerform a Simple Upload. - Multipart upload:
uploadType=multipart
. For quick transfer of a small file(5 MB or less) and metadata that describes the file, all in a single request. Toperform a multipart upload, refer toPerform a Multipart Upload. - Resumable upload:
uploadType=resumable
. For more reliable transfer,especially important with large files. Resumable uploads area good choice for most applications, since they also work for small filesat the cost of one additional HTTP request per upload. To perform a resumableupload, refer toPerform a Resumable Upload.
Most Google API client libraries implement at least one of the methods. Referto the client library documentation for additional details on how to useeach of the methods.
Perform a simple upload
A simple upload is the most straightforward way to upload a file.Use this option if:
- the file is small enough to upload again in its entirety if the connectionfails.
- there is no metadata to send or if you plan to send metadata in a separate request.
If you need to provide metadata for the file, you can usea multipart upload or resumable upload instead.
For larger files (more than 5 MB) or less reliable networkconnections, use the resumable upload.
These examples show how to upload an image using the client libraries:
Send a simple upload request
To use simple upload:
- Create a
POST
request to the method's/upload
URI. To update an existingfile, usePUT
. - Add the query parameter
uploadType=media
.For example: - Add the file's data to the request body.
- Add these HTTP headers:
Content-Type
. Set to the MIME media type of the object being uploaded.Content-Length
. Set to the number of bytes you upload. Thisheading is not required if you use chunked transferencoding.
- Send the request.
Example: Send a simple upload request
This example shows a simple upload request:
![Hosting Hosting](/uploads/1/2/6/2/126247002/316266839.png)
If the request succeeds, the server returns the HTTP
200 OK
status code alongwith the file's metadata:A blob uploaded to Drive gets 'Untitled' as the default title.For information about how to handle errors, refer to Handle errors.
Perform a multipart upload
A multipart upload request allows you to send metadata along with the datato upload. Use this option if the data you send is small enough to uploadagain in its entirety if the connection fails.
If your file does not have any metadata, use simple uploadinstead. For larger files (more than 5 MB) or less reliable network connections,use resumable upload instead.
Send a multipart upload request
To use multipart upload:
- Create a
POST
request to the method's/upload
URI. To update anexisting file, usePUT
. - Add the query parameter
uploadType=multipart
.For example: - Create the body of the request. Format the body according to the
multipart/related
content type [RFC 2387], which contains two parts:- Metadata part. Must come first, and must have a
Content-Type
headerset toapplication/json; charset=UTF-8
. Add the file's metadata to thispart in JSON format. - Media part. Must come second, and must have a
Content-Type
header,which may have any MIME type. Add the file's data to this part.
Identify each part with a boundary string, preceded by two hyphens. Inaddition, add two hyphens after the final boundary string. - Metadata part. Must come first, and must have a
- Add these top-level HTTP headers:
Content-Type
. Set tomultipart/related
, and include the boundarystring you're using to identify the different parts of the request. Forexample:Content-Type: multipart/related; boundary=foo_bar_baz
Content-Length
. Set to the total number of bytes in the request body.
- Send the request.
POST
or PUT
request to the standard resourceendpoint: https://www.googleapis.com/drive/v3/files
Example: Send a multipart upload request
This example shows a multipart upload request:
If the request succeeds, the server returns the HTTP
200 OK
status code alongwith the file's metadata:To handle errors, refer to Handle errors.
Perform a resumable upload
This protocol allows you to resume an upload operation after acommunication failure interrupts the flow of data. Use this option if:
- You transfer large files.
- The likelihood of a network interruption or some other transmission failureis high (for example, if you upload a file from a mobile app).
Resumable uploads can also reduce your bandwidth usage when there is a networkfailure, because you don't have to restart large file uploads from thestart.
If you send small files over a reliable network connection, you can usesimple upload or multipart upload instead.
Learn about request URIs
When you upload media, you use a special URI. In fact, methods that supportmedia uploads have two URI endpoints:
- The
/upload
URI, for the media. The format of the/upload
endpoint is thestandard resource URI with an/upload
prefix. Use this URI when you transferthe media data itself. Example:POST /upload/drive/v3/files
. - The standard resource URI, for the metadata. If the resource contains anydata fields, those fields store metadata that describes the uploadedfile. You can use this URI to create or update metadata values.Example:
POST /drive/v3/files
.
Initiate a resumable upload session
To initiate a resumable upload session:
- Create a request to the method's
/upload
URI. To create a new file, usePOST
. To update an existing file, usePUT
. - Add the query parameter
uploadType=resumable
.For example:or: - If you have metadata for the file, add the metadata to the request body inJSON format. Otherwise, leave the request body empty.
- Add these HTTP headers:
X-Upload-Content-Type
. Optional. Set to the MIME type of the file data,which will be transferred in subsequent requests. If the MIME type of thedata is not specified in metadata or through this header, the object willbe served asapplication/octet-stream
.X-Upload-Content-Length
. Optional. Set to the number of bytes of filedata, which will be transferred in subsequent requests.Content-Type
. Required if you have metadata for the file. Set toapplication/json; charset=UTF-8
.Content-Length
. Required unless you use chunked transferencoding. Set to the number of bytes in the body of thisinitial request.
- Send the request.
Example: Initiate a resumable upload session
This example shows how to initiate a resumable session to uploada new file:
The next section describes how to handle the response.
Save the resumable session URI
If the session initiation request succeeds, the response includes a
Note: A resumable session URI expires after one week.200 OK
HTTP status code. In addition, it includes a Location
header that specifiesthe resumable session URI. Use the resumable session URI to upload the file dataand query the upload status.Copy and save the resumable session URI so you can use it for subsequentrequests.
Example: Save the resumable session URI
This example shows a response that includes a resumable session URI:
Upload the file
There are two ways to upload a file with a resumable session:
- In a single request. This approach is usually best, since it requiresfewer requests and thus has better performance.
- In multiple chunks. Use this approach if:
- You need to reduce the amount of data transferred in any single request.You might need to do this when there is a fixed time limit for individualrequests, as is true for certain classes of Google App Engine requests.
- You need to provide a customized indicator to show the upload progress.
Single request
To upload the file in a single request:
- Create a
PUT
request to the resumable session URI. - Add the file's data to the request body.
- Add a
Content-Length
HTTP header, set to the number of bytes in thefile. - Send the request.
If the upload request is interrupted, or if you receive a
5xx
response,follow the procedure in Resume an interrupted upload.Multiple chunks
To upload the file in multiple chunks:
- Create a
PUT
request to the resumable session URI. - Add the chunk's data to the request body. Create chunks in multiples of256 KB (256 x 1024 bytes) in size, except for the final chunk that completesthe upload. Keep the chunk size as large as possible so that the upload isefficient.
- Add these HTTP headers:
Content-Length
. Set to the number of bytes in the current chunk.Content-Range
: Set to show which bytes in the fileyou upload. For example,Content-Range: bytes 0-524287/2000000
shows that you upload the first 524,288 bytes (256 x 1024 x 2) ina 2,000,000 byte file.
- Send the request, and process the response.If the upload request is interrupted, or if you receive a
5xx
response, follow the procedure in Resume an interruptedupload. - Repeat steps 1 through 4 for each chunk that remains in the file. Use the
Range
header in the response to determine where to start the next chunk.Do not assume that the server received all bytes sent in the previousrequest.When the entire file upload is complete, you receive a200 OK
or201Created
response, along with any metadata associated with the resource.
Example: Upload the file
Single request
This example shows a resumable request to upload an entire2,000,000-byte JPEG file, and uses the resumable session URI obtained in theprevious step:
If the request succeeds, you receive a
200 OK
or 201 Created
response,along with any metadata associated with the resource.Multiple chunks
This example shows a request that sends the first 524,288 bytes(512 KB) of the file, and uses the resumable session URI obtained in theprevious step:
If the request succeeds, the server responds with
308 Resume Incomplete
,along with a Range
header that identifies the total number of bytes thathave been stored so far:Use the upper value returned in the
Range
header to determine where tostart the next chunk. Continue to PUT
each chunk of the file until theentire file has been uploaded.When the entire upload is complete, you receive a
200 OK
or 201 Created
response, along with any metadata associated with the resource.Resume an interrupted upload
If an upload request is terminated before a response, or if youreceive a
503 Service Unavailable
response, then you need to resume theinterrupted upload. To do this:- To request the upload status, create an empty
PUT
request to the resumablesession URI. - Add a
Content-Range
header to indicate that the current position in the fileis unknown.For example, set theContent-Range
to*/2000000
if your totalfile length is 2,000,000 bytes.If you don't know the full size of the file, set theContent-Range
to*/*
. - Send the request.
- Process the response.
- A
200 OK
or201 Created
response indicates that the upload wascompleted, and no further action is necessary. - A
308 Resume Incomplete
response indicates that you need to continueto upload the file. - A
404 Not Found
response indicates the upload session has expired and theupload needs to be restarted from the start.
- A
- If you received a
308 Resume Incomplete
response, process the response'sRange
header, which specifies which bytes the server has received so far. Theresponse will not have aRange
header if no bytes have been received yet.For example, aRange
header ofbytes=0-42
indicates that the first43 bytes of the file have been received. - Now that you know where to resume the upload, continue to upload the file,either send the data that remains or send the next chunk. Include a
Content-Range
header to indicate which portion of the file you send.For example,Content-Range: bytes 43-1999999/2000000
indicates that yousend bytes 43 through 1,999,999.
Example: Resume an interrupted upload
This example shows a request for the upload status:
The server's response uses the
Range
header to indicate that it has receivedthe first 43 bytes of the file so far:You can then send a request to resume the upload. Send the bytes that remain in the file. Start at byte 43:
Handle errors
When you upload media, be sure to follow these best practices related to handle errors:
- Resume or retry uploads that fail due to connection interruptions or any 5xxerrors, for example:
- 500 Internal Server Error
- 502 Bad Gateway
- 503 Service Unavailable
- 504 Gateway Timeout
- Resume or retry uploads that fail due to 403 rate limit errors.
- Use an exponential backoff strategy if any 403 or 5xx server error isreturned when upload requests retry or resend. These errors can occurif a server gets overloaded. Exponential backoff can help alleviatethese kinds of problems when there is a high volume of requests or heavynetwork traffic.
- (Resumable uploads only) Restart uploads if a
404 Not Found
error isreceived after it resumes or uploads a chunk. This indicates theupload session has expired and must be restarted from the start. Uploadsessions expire after 1 week of inactivity.
For additional details, see Handling API Errors.
Import to Google Docs types
When you create a file in Google Drive, you can convert some types file into aGoogle Docs, Sheets or Slides document. Specify themimeType
file property.This sample shows how to upload a CSV file as a spreadsheet:The supported conversions are available dynamically in theAbout resource's
importFormats
arrayand include:From | To |
---|---|
Microsoft Word, OpenDocument Text, HTML, RTF, plain text | Google Docs |
Microsoft Excel, OpenDocument Spreadsheet, CSV, TSV, plain text | Google Sheets |
Microsoft Powerpoint, OpenDocument Presentation | Google Slides |
JPEG, PNG, GIF, BMP, PDF | Google Docs (embeds the image in a Doc) |
plain text (special MIME type), JSON | Google Apps Script |
When you upload and convert media during an
update
request to a Google Doc,Sheet, or Slide the full contents of the document will be replaced.When you convert images you can improve the quality of the OCR algorithm. Specify the applicable BCP 47 languagecode in the
ocrLanguage
parameter. The extracted text will appear in the Google Docs documentalongside the embedded image.Use a pregenerated ID to upload files
The Drive API allows you to retrieve a list of pregenerated file IDsthat can be used to upload and create resources. Upload and file creationrequests can then include these pregenerated IDs. Set the
id
fieldsin the file metadata.You can safely retry uploads with pregenerated IDs in the case of anindeterminate server error or timeout. If the file was successfullycreated, subsequent retries return a
HTTP 409
error, it does not create duplicate files.Note: Pregenerated IDs are not supported for native Google Document creation, oruploads where conversion to native Google Document format is requested.
![](/uploads/1/2/6/2/126247002/787306048.png)