Uploaded Files Via POST


#1

Does anyone have any examples of posting files to the local storage? The documentation in the Git Wiki is shall we say, a tad light:-

https://github.com/dreamfactorysoftware/dsp-core/wiki/File-Storage-Services

I’m trying to create an area for users to upload an image to use as a profile picture using the ng-flow extension.

How does the DSP govern permissions for each container/directory/file too?

Thanks


#2

2 headers required with a file upload, here’s the jquery way ->

$.ajax({
    beforeSend: function(request) {
        request.setRequestHeader("X-File-Name", file.name);
        request.setRequestHeader("Content-Type", file.type);
    },
    type :'POST',
    url :{yourdspurl}/rest/files/{container}/{file_path} createFile()
    data: yourfile,
    cache:false,
    processData: false
});

Security is at the container level currently, not down to the folder/file level.

Documentation forthcoming.


#3

Hey Antony, Ben here. If you need visibility control of the image at the file level (e.g. user can only see his own image), one option would be to store the image in the db and use record-level permissions to enforce that rule.


#4

Angular Way

http://jsfiddle.net/specialjyo/a0umb9js/1/


#5

Thanks for the help guys, I was planning on tackling this today and @Jason your example is the cherry on top!


#6

Also take a look at Jenny’s blog post linked from the wiki https://github.com/dreamfactorysoftware/dsp-core/wiki/File-Storage-Services


#7

It works!:heart_eyes:
thanks!


#8

HI Ben!
The link that you posted isn’t working anymore. Would there happen to be another example link similar?


#9

@drexelsharp Sorry about that. This info in the docs should be helpful:

http://wiki.dreamfactory.com/DreamFactory/Features/Files
http://wiki.dreamfactory.com/DreamFactory/Tutorials/Uploading_File
http://wiki.dreamfactory.com/DreamFactory/Tutorials/Downloading_File
http://wiki.dreamfactory.com/DreamFactory/Tutorials/Deleting_File
http://wiki.dreamfactory.com/DreamFactory/Tutorials/Adding_a_text_file