Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw data mode. is it possible? (dropbox upload problem) #1848

Open
abolabo opened this issue Nov 28, 2023 · 1 comment
Open

Raw data mode. is it possible? (dropbox upload problem) #1848

abolabo opened this issue Nov 28, 2023 · 1 comment

Comments

@abolabo
Copy link

abolabo commented Nov 28, 2023

Hi.
Your plugin is great.
Thank you your good work.

I got a problem with uploading files on dropbox via ajax.
I had changed http-headers with 'filepreajax', added bearer token and some custom header of dropbox

plugin.ajaxSettings =
                    {
                        headers: {
                            'Authorization': "Bearer **********************************",
                            'Content-Type': 'application/octet-stream',
                            'Dropbox-API-Arg': JSON.stringify({
                                path: fileUploadPath,
                                mode: 'add',
                                autorename: true,
                                mute: false
                            })
                        }
                    };

Problem is in data on dropbox side. If i send jpeg file it cannot be previewed on their side.
Content of file is


-----------------------------188311213513021448531462969784
Content-Disposition: form-data; name="order_files"; filename="tiger-invert.jpg"
Content-Type: image/jpeg

\FF\D8\FF\E0\00�JFIF\00���\00H\00H\00\00\FF\E1-\9AExif\00\00II*\00�\00\00\00�\00���\00�\00\00\00�\00\00\00���\00�\00\00\00b\00\00\00���\00�\00\00\00j\00\00\00(��\00�\00\00\00�\00\00\001��\00
\00\00\00r\00\00\002��\00�\00\00\00\80\00\00\00i\87�\00�\00\00\00\94\00\00\00\A6\00\00\00H\00\00\00�\00\00\00H\00\00\00�\00\00\00GIMP 2.10.30\00\002022:07:11 11:34:24\00�\00�\A0�\00�\00\00\00�\00\00\00\00\00\00\00	\00\FE\00�\00�\00\00\00�\00\00\00\00��\00�\00\00\00\FA\00\00\00���\00�\00\00\00\00�\00\00���\00�\00\00\00��\00\00���\00�\00\00\00�\00\00\00���\00�\00\00\00�\00\00\00���\00�\00\00\00�\00\00\00���\00�\00\00\00��\00\00���\00�\00\00\00t,\00\00\00\00\00\00�\00�\00�\00\FF\D...

As you see plugin adds headers as content.

Is there way to set "raw"-mode for sending file via ajax?

Dropbox documentation suggest do this

        xhr.open('POST', 'https://content.dropboxapi.com/2/files/upload');
        xhr.setRequestHeader('Authorization', 'Bearer ************');
        xhr.setRequestHeader('Content-Type', 'application/octet-stream');
        xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({
            path: '/111/' + file.name,
            mode: 'add',
            autorename: true,
            mute: false
        }));
        xhr.send(file);

where file is an file object.

@kartik-v
Copy link
Owner

kartik-v commented Apr 9, 2024

Recommend - for such cases - you should write an intermediate middleware web server API that reads the standard FILE upload request from this plugin (just like how you would from a HTML native file input) and then from the middleware call the custom dropbox API to transform/ upload files to the cloud with the necessary settings, file conversions and the necessary access authorizations. It maybe difficult to standardize this at plugin level as to what is needed by which cloud upload vendor. Open to suggestions though if anything else can be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants