Uploading File

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsUploading File
 
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
DreamFactory 2.0 allows you to expose various storage services as API Endpoints. The following storage services are currently  
+
DreamFactory allows you to expose various storage services as API Endpoints. The following storage services are currently  
supported.
+
supported:
  
 
* Local Storage (configurable to use local file system, S3, Azure, or Rackspace)
 
* Local Storage (configurable to use local file system, S3, Azure, or Rackspace)
Line 10: Line 10:
 
=== Provisioning a Storage Service ===
 
=== Provisioning a Storage Service ===
  
All DreamFactory 2.0 instances come pre-configured with a 'Local Storage' service named 'files'. You can find this service  
+
All DreamFactory instances come pre-configured with a 'Local Storage' service named 'files'. You can find this service  
 
on the admin console, under the services tab. You can also provision as many other storage services as you like using the  
 
on the admin console, under the services tab. You can also provision as many other storage services as you like using the  
admin console. Login to the admin console and select the 'Services' tab. Click on the 'Create' button from the left menu.  
+
admin console.  
On the service creation form select your storage type from the 'Service Type' drop down box (File section). Enter a short,  
+
 
 +
Log in to the admin console and select the 'Services' tab. Click on the 'Create' button from the left menu.  
 +
On the service creation form, select your storage type from the 'Service Type' drop down box (File section). Enter a short,  
 
one-word, meaningful name for your service as well as a label and description. Depending on which storage type you pick,  
 
one-word, meaningful name for your service as well as a label and description. Depending on which storage type you pick,  
 
you will need to enter the service configuration values on the 'Config' tab. Create your storage service after entering all  
 
you will need to enter the service configuration values on the 'Config' tab. Create your storage service after entering all  
your configuration values. Your storage service is now ready for action. For this tutorial, we will use the pre-configured  
+
your configuration values. Your storage service is now ready for action.  
storage service - 'files'.
+
 
 +
For this tutorial, we will use the pre-configured storage service - 'files'.
  
 
=== API Endpoints ===
 
=== API Endpoints ===
 +
* '''Important Note''': When uploading your file as multipart/form-data be sure to set the key name in the form to <code>files</code>.
  
 
==== Uploading a binary file ====
 
==== Uploading a binary file ====
  
Uploading a file using URL
+
Uploading a file using URL:
  
 
<pre>POST http://{url}/api/v2/{storage_service_name}?url={remote_url}</pre>
 
<pre>POST http://{url}/api/v2/{storage_service_name}?url={remote_url}</pre>
  
Uploading a file using form post
+
Uploading a file using form post:
  
 
<pre>POST http://{url}/api/v2/{storage_service_name}
 
<pre>POST http://{url}/api/v2/{storage_service_name}
Line 42: Line 46:
 
==== Uploading a zip file and extracting its content ====
 
==== Uploading a zip file and extracting its content ====
  
Uploading a zip file using URL
+
Uploading a zip file using URL:
  
 
<pre>POST http://{url}/api/v2/{storage_service_name}?url={remote_url}&extract=true</pre>
 
<pre>POST http://{url}/api/v2/{storage_service_name}?url={remote_url}&extract=true</pre>
  
Uploading a zip file using form post
+
Uploading a zip file using form post:
  
 
<pre>POST http://{url}/api/v2/{storage_service_name}?extract=true
 
<pre>POST http://{url}/api/v2/{storage_service_name}?extract=true
Line 61: Line 65:
 
==== Delete existing folder content before uploading a zip file and extracting its content ====
 
==== Delete existing folder content before uploading a zip file and extracting its content ====
  
Uploading a zip file using URL
+
Uploading a zip file using URL:
  
 
<pre>POST http://{url}/api/v2/{storage_service_name}?url={remote_url}&extract=true&clean=true</pre>
 
<pre>POST http://{url}/api/v2/{storage_service_name}?url={remote_url}&extract=true&clean=true</pre>
  
Uploading a zip file using form post
+
Uploading a zip file using form post:
  
 
<pre>POST http://{url}/api/v2/{storage_service_name}?extract=true&clean=true
 
<pre>POST http://{url}/api/v2/{storage_service_name}?extract=true&clean=true
Line 77: Line 81:
 
-- <file content> --
 
-- <file content> --
 
</pre>
 
</pre>
 
  
 
=== Example - Upload a JPEG image to a directory called images using storage service called 'files' ===
 
=== Example - Upload a JPEG image to a directory called images using storage service called 'files' ===
Line 86: Line 89:
 
* Request URL:
 
* Request URL:
 
<pre>POST http://foo.com/api/v2/files/images/?url=http://example.com/images/profile_picture.jpg</pre>
 
<pre>POST http://foo.com/api/v2/files/images/?url=http://example.com/images/profile_picture.jpg</pre>
 +
 +
=== Example - Upload a JPG image as a base64 encoded string  to a directory called images using storage service called 'files' ===
 +
 +
* Storage service: files
 +
* Destination directory:images/
 +
* JPEG image has been converted to a base64 encoded string
 +
* Request URL:
 +
<pre>POST http://foo.com/api/v2/files/images/</pre>
 +
* Request Payload:
 +
<pre>{
 +
"resource": [{
 +
"name": "filename.jpg",
 +
"type": "file",
 +
"is_base64": true,
 +
"content": "base 64 encoded string goes here"
 +
}]
 +
}</pre>
  
 
=== Example - Upload a zip file to a directory called documents using storage service called 'files' and extract it. ===
 
=== Example - Upload a zip file to a directory called documents using storage service called 'files' and extract it. ===

Latest revision as of 15:26, 25 July 2019

DreamFactory allows you to expose various storage services as API Endpoints. The following storage services are currently supported:

  • Local Storage (configurable to use local file system, S3, Azure, or Rackspace)
  • AWS S3
  • Azure Blob
  • OpenStack Object Storage
  • Rackspace Cloud Files

Provisioning a Storage Service

All DreamFactory instances come pre-configured with a 'Local Storage' service named 'files'. You can find this service on the admin console, under the services tab. You can also provision as many other storage services as you like using the admin console.

Log in to the admin console and select the 'Services' tab. Click on the 'Create' button from the left menu. On the service creation form, select your storage type from the 'Service Type' drop down box (File section). Enter a short, one-word, meaningful name for your service as well as a label and description. Depending on which storage type you pick, you will need to enter the service configuration values on the 'Config' tab. Create your storage service after entering all your configuration values. Your storage service is now ready for action.

For this tutorial, we will use the pre-configured storage service - 'files'.

API Endpoints

  • Important Note: When uploading your file as multipart/form-data be sure to set the key name in the form to files.

Uploading a binary file

Uploading a file using URL:

POST http://{url}/api/v2/{storage_service_name}?url={remote_url}

Uploading a file using form post:

POST http://{url}/api/v2/{storage_service_name}

Request header:
...
Content-Type: multipart/form-data;
...

Request payload:
-- <file content> --

Uploading a zip file and extracting its content

Uploading a zip file using URL:

POST http://{url}/api/v2/{storage_service_name}?url={remote_url}&extract=true

Uploading a zip file using form post:

POST http://{url}/api/v2/{storage_service_name}?extract=true

Request header:
...
Content-Type: multipart/form-data;
...

Request payload:
-- <file content> --

Delete existing folder content before uploading a zip file and extracting its content

Uploading a zip file using URL:

POST http://{url}/api/v2/{storage_service_name}?url={remote_url}&extract=true&clean=true

Uploading a zip file using form post:

POST http://{url}/api/v2/{storage_service_name}?extract=true&clean=true

Request header:
...
Content-Type: multipart/form-data;
...

Request payload:
-- <file content> --

Example - Upload a JPEG image to a directory called images using storage service called 'files'

POST http://foo.com/api/v2/files/images/?url=http://example.com/images/profile_picture.jpg

Example - Upload a JPG image as a base64 encoded string to a directory called images using storage service called 'files'

  • Storage service: files
  • Destination directory:images/
  • JPEG image has been converted to a base64 encoded string
  • Request URL:
POST http://foo.com/api/v2/files/images/
  • Request Payload:
{
	"resource": [{
		"name": "filename.jpg",
		"type": "file",
		"is_base64": true,
		"content": "base 64 encoded string goes here"
	}]
}

Example - Upload a zip file to a directory called documents using storage service called 'files' and extract it.

POST http://foo.com/api/v2/files/documents/?url=http://example.com/docs.zip&extract=true

Example - Delete existing directory content before uploading a zip file and extracting it.

POST http://foo.com/api/v2/files/images/?url=http://example.com/docs.zip&extract=true&clean=true