I’m sure this is a pretty basic question that isn’t entirely specific to Dreamfactory, but what techniques are expected to be used to send a create file / create folder request to the API that contains both the json parameters, and binary data?
I’m currently using the JS SDK and an HTML form, and although I can create empty files via a combination of url parameters attached to a POST action with a file input, the file itself is never uploaded. The live API docs say the body of the request should contain the file data when creating a single file - does this mean I should encode as base64 or similar and attach a {body: xxxxx} object to the request, ignoring the FileRequest schema? Is creating a folder from a zip only possible when loading a file from an existing online URL?
Thanks for the response - I think my issue is probably with my understanding more than a bug though.
It seems like the API docs say a file can be uploaded as the body of the POST request to the createFile/createFolder URLs. Unless I am reading it wrong and this interface is only to alert the DSP to files uploaded by some other means.
I think when I am uploading a file via a form it is attached as formdata rather than binary in the body of the request. I was wondering what the most common method used to upload files from a user to local storage via the API was. I assumed forms, as other approaches would require JS FileReader etc.
So far I have tried variations of both
var file = document.getElementById("file").files[0]; //from form
window.df.apis.app.createFile({"container": "app", "file_path": "temp.zip", "body":file});
My apologies for the delay. I’ve reached out to engineering but would like you to send me an email to mark@dreamfactory.com - that way we can work with you directly. Might as well take advantage of the free 30 days of support.
We to are having the same problem. If we use the createFile API, a file gets created on the server but is an empty file. I think the problem is on how the body parameter is assembled. From the mobile device the most likely scenario is to use a file picker to pick the file then update the database and also create a file on the server. Are there any examples on how to format the body parameter of the createFile API properly?
When creating a file using a POST within the Live API try the following… Notice to the right of the “body” field that there is a “model schema” option that can be chosen. When clicking on this (make sure the body field is empty), it will automatically copy over the schema template for you to use.
This is true with all of our POST requests, but in this particular case the model schema is:
container : Name of the container where the file exists.
This is confusing since I am trying to upload a file and this should not exist yet on the container
file_path: Path and name of the file to create.
Is this the container + filename?
Since for createFile these are the only required parameters, I would think that container parameter should be the destination container for the upload and file_path would be the source file_path+filename of the file we want to upload.
The wiki for CreateFile is still empty. It would be great if you can give us an example of the parameter setup plus body content given a destination container and the path of the local file file we want to upload.
I was able to recreate your specific scenario and get proper results. This screenshot is from the online file storage:
[The image you are requesting does not exist or is no longer available]
And this is my successful GET on this image file:
[The image you are requesting does not exist or is no longer available]
So, I’ve been able to replicate your issue successfully - please send me an email to support@dreamfactory.com if you are still unable to get this working.
Adding dormfinder to the path_file still gives a 404. Could this be a v1.5.9 issue?
[The image you are requesting does not exist or is no longer available]
We moved over to v1.6.10 already. We do not have a problem with GetFile(). We are able to retrieve an image and show it on a mobile phone. The problem we have is with using CreateFile() to try to upload an image. In jQuery Mobile we use :file Selector to select the image we want to upload.
Do we just fill up name, path, content_type. Is my assumption correct?
name: name of file when uploaded to the service
path: path of file including filename of the file on the mobile phone
content_type: of file to upload
metadata: ? do I have to read the file and convert it to base64 and put the result in metadata?
A code example would be greatly appreciated.
We are currently able to upload an image using the FORM POST method above but the problem with this method is the response goes to response page that shows the name of the file and path, which we do not want.
Hello, I am looking for solution how to upload image jpeg from android (iPhone also) application to dreamfactory in binary format. But with current android sdk from dreamfactory I can only use function createFile with json parameter, where image data I have to convert to base64.
How can I do this directly in binary format ?
Hi,
In current version of Android SDK, I cann’t add headers in FilesAppi.createFile(…), so I created new function createFile in my derived class, where I add your two request header.
As I want it for image upload, I setup content type to ‘image/jpeg’ and body is byte array.
Here is code:
Response is ok, dsp create file on server, but content is textual not binary. Content is converted in base64 string by dsp.
I need programmatically upload binary file same way as I can do this with dsp file manager action “Upload File”. When I use this form action, image file on server is stored in binary format.