Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6332311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:14:21+00:00 2026-05-24T18:14:21+00:00

I have an interesting problem that I’m trying to solve and was wondering if

  • 0

I have an interesting problem that I’m trying to solve and was wondering if any of you could give me a hand.

I’m building a little tool that allows users to Drag and Drop files into our CMS. Whilst I’ve got the Drag and Drop part is working fine (using the new HTML5 APIs) I’m stuck in terms of how the file upload should work, especially since my constraint is that I cannot modify any of the server’s functions. I’ve looked at all other examples and they all relatively have simple uses cases where they just send the file data across, without having to convert everything to multipart/form-data, etc.

At the moment the server has a simple form that looks a bit like so:

Name: [ input=text ]
File: [ input=file ]
Caption: [ textarea ]

When a user hits the “Save” button, a POST call is issued of content type multipart/form-data.

Originally I was thinking I could just replace the current input control with my own hidden one (using the same “name” attribute) and just have the base64 encoded data as the “value”, however the CMS expects a “filename” to be passed through, which normally is taken care of by the input=file. So for example, the final post looks a bit like so:

Content-Disposition: form-data; name="image_0"; filename="assets.jpg" 

Content-Type: image/jpeg

<Some binary image data here>

Am I going about this completely the wrong way? Should I be just using the XHR object instead?

Cheers

  • 1 1 Answer
  • 4 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:14:21+00:00Added an answer on May 24, 2026 at 6:14 pm

    I worked it out.

    Here’s what I did and my references:

    • Sending multipart/formdata with jQuery.ajax
    • https://developer.mozilla.org/En/Using_XMLHttpRequest#Using_FormData_objects
    • https://developer.mozilla.org/en/DOM/File

    I had to use the FormData object (available in Firefox 4+, Safari 5+ and Google Chrome) and of course the FileReader object.

    Here is the implementation (with jQuery):

    // The file object needs to come from the "drop" event and is read by the "FileReader" object with the readAsBinaryString() function.
    // var file = null;
    
    var data = new FormData();
    $("#main_form input:not([type=file])").each(function(){
        data.append($(this).attr("name"), $(this).val());
    });
    data.append("image_0", file);
    $.ajax({
        url: $("#main_form").attr("action"),
        type: "POST",
        data: data,
        processData: false,
        contentType: false
    });
    

    At the moment IE isn’t an issue, but will be soon (since I need to port this extension to IE). Is there a better way to do this for IE?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interesting genetics problem that I would like to solve in native
I have an interesting problem here I've been trying to solve for the last
We have an interesting problem that I was hoping someone could help to shed
I have an interesting problem to solve here that may require some creative direction.
I have an interesting SQL problem that I need help with. Here is the
I have an interesting problem. The basis of the problem is that my last
I have an interesting problem, which is a function that returns a Dictionary<String,HashSet<String>> .
I have an interesting problem, that i am sure has a simple answer, but
I have an interesting problem to solve. One of my clients has me developing
I have an interesting problem trying to represent complex schedule data in a database.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.