0

I have a script that I'm working on, this script reads a zip file and extracts the contents of the files inside the zip. What I'm trying to do is send a request to my server in the following format:

file0name,contentfile0;file1name,contentfile1;file2name,contentfile2

Can someone tell me what type of data structure I should use? Is it a list or a JSON object?

https://jsfiddle.net/ker1w6pb/6/

10
  • 1
    json for sure... it can have a list inside it. Commented Nov 24, 2015 at 16:18
  • 1
    Can you share some more details? I'm interested how you're going to use JavaScript to "read...and extract the contents" of a zip file in client side JavaScript? Commented Nov 24, 2015 at 16:20
  • 1
    Are you putting content into a string? (confused) Commented Nov 24, 2015 at 16:21
  • 1
    What you send to the server is a string. How you build and parse it is up to you. Commented Nov 24, 2015 at 16:23
  • 2
    I have no idea what you are asking. Since you say "send a request to my server", presumably you are talking about a client-side script, but JS on the client side cannot read a zip or any other file. How you send what to the server is completely up to you. For instance, you could send it as a form-like POST. Commented Nov 24, 2015 at 16:25

1 Answer 1

2

Assuming you convert your content into a string (which sounds odd to me), you can just POST a JSON data object containing your string:

var postData = [{
  filename: 'file0',
  content: 'content0'
}, {
  filename: 'file1',
  content: 'content1'
}, {
  filename: 'file2',
  content: 'content2'
}];

var postString = postData.reduce(function(previous, current) {
  return previous + current.filename + ',' + current.content + ';';
}, '');

//post(uri, {data: postString});
document.write(postString);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.