Highlighted

How do I accept file upload through rest api

New Here ,
Jun 09, 2014

Copy link to clipboard

Copied

I am attempting to implement a REST endpoint that accepts a multi-part form request that includes form data as well as a file upload. Is that even possible? Is it possible to just accept a file upload and nothing else (e.g. specify a unique ID in the URL and POST/PUT data in the request body)? I've tried numerous things and have been unable to successfully implement a REST endpoint that accepts a file upload...

  • Specify a CFARGUMENT type="binary" to the CFFUNCTION that is the REST endpoint definition. This results in a CF REST API compile error.
  • Submit a multipart/form-data POST/PUT request and use CFFILE to handle the file upload in the body of the CFFUNCTION. This causes the CF REST framework to not see any of the form-field parameters that are required by CFARGUMENT tags.
  • Uploading the file to a separate endpoint that expects only the file and setting the HTTP content-type header to the file's MIME type. The CF REST framework rejects this because it wants a specific content-type (presumably multipart/form-data or application/x-www-form-urlencoded).

Views

1.5K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

How do I accept file upload through rest api

New Here ,
Jun 09, 2014

Copy link to clipboard

Copied

I am attempting to implement a REST endpoint that accepts a multi-part form request that includes form data as well as a file upload. Is that even possible? Is it possible to just accept a file upload and nothing else (e.g. specify a unique ID in the URL and POST/PUT data in the request body)? I've tried numerous things and have been unable to successfully implement a REST endpoint that accepts a file upload...

  • Specify a CFARGUMENT type="binary" to the CFFUNCTION that is the REST endpoint definition. This results in a CF REST API compile error.
  • Submit a multipart/form-data POST/PUT request and use CFFILE to handle the file upload in the body of the CFFUNCTION. This causes the CF REST framework to not see any of the form-field parameters that are required by CFARGUMENT tags.
  • Uploading the file to a separate endpoint that expects only the file and setting the HTTP content-type header to the file's MIME type. The CF REST framework rejects this because it wants a specific content-type (presumably multipart/form-data or application/x-www-form-urlencoded).

Views

1.5K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 09, 2014 0
Adobe Community Professional ,
Jun 11, 2014

Copy link to clipboard

Copied

The following method, unlike those above, will work. It requires you to know the MIME type of the binary file you wish to upload. This example uploads a PDF document.

uploader.cfm

<cfset restInitApplication(expandPath("."))>

<cfhttp url="http://localhost:8500/rest/myRestApp/myService" method="post">

    <cfhttpparam file="C:\temp\testDoc.pdf" mimetype="application/pdf" name="myFile" type="file">

</cfhttp>

service.cfc

<cfcomponent rest="true" restpath="/myService">

<cffunction name="getFile" access="remote" httpMethod="POST" returntype="string">

<cffile action="upload" accept="application/pdf" filefield="myFile" nameconflict="overwrite" destination="C:\Users\BKBK\Desktop\testFile.pdf">

<cfreturn "File uploaded!">

</cffunction>

</cfcomponent>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 11, 2014 0
New Here ,
Jun 11, 2014

Copy link to clipboard

Copied

We need to allow all file types to be uploaded. We cannot constrain ourselves to just a few file types.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 11, 2014 0
Adobe Community Professional ,
Jun 11, 2014

Copy link to clipboard

Copied

No problem at all. Use the wildcard for MIME type, as follows:

<cfhttpparam mimetype="*">

<cffile accept="*">

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 11, 2014 0
Adobe Community Professional ,
Jun 12, 2014

Copy link to clipboard

Copied

Did the wildcards help?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 12, 2014 1
Explorer ,
Jun 17, 2015

Copy link to clipboard

Copied

Has there been any useful update to this post?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 17, 2015 0