Forums » General Discussion Search

Server Error on Upload New Reply

Author Post
Posts: 7
Registered: Dec 19, 2008

Hello, I'm new to the EchoNest API. I've built a post request with the file as the content of the request.

Here are the headers:

POST /api/upload?api_key=XXXXXXXXXXXXXX&version=3&wait=Y HTTP/1.0 Host: developer.echonest.com User-Agent: moaec_echonest_hook 0.1 Content-Type: audio/mpeg Content-Length: 4392889 Connection: Close

I've tried with a few different MP3 files, I believe each was encoded using LAME, but I tried files from different sources as a sanity check. Each request returns a Server Error. Any help would be appreciated.

Posts: 17
Registered: Oct 08, 2008

The POST request should be made with the file as an attachment to the request with the variable name "file," not as the request itself.

Posts: 7
Registered: Dec 19, 2008

I'm not sure what you mean by 'as an attachment'. My initial thought is of multipart http messages, but this only has one part, I believe. Am I to add this file data in the query string? Does it need to by uuencoded?

Thank You Again

Posts: 7
Registered: Dec 19, 2008

Ok, I continue to try sending this different ways, but no joy. Here is the format of my latest request:

POST /api/upload HTTP/1.1 Host: developer.echonest.com User-Agent: moaec_echonest_hook 0.1 Content-Type: application/x-www-form-urlencoded Content-transfer-encoding: text Content-Length: 20300536 Connection: Close

api_key=XXXXXXXXXXX&version=3&file=YYYYYYYYY

where XXX is my key and YYY is my url_encoded MP3 file. I Get an XML message back with all the parameters except 'file', and a message 'Missing Parameter: "file".

Am I even close? Is there somewhere an example of an upload request? Thank You

Posts: 4
Registered: Feb 20, 2009

Hi There,

I have this same problem:

"Server Error" "There was an error processing your request."

can please explain what you mean with:

The POST request should be made with the file as an attachment to the request...

and what you mean with:

..with the variable name "file," not as the request itself.

Actually some sample text showing the request as it should be will be of great help.

Thanks!

Posts: 90
Registered: Aug 29, 2008

Would this be better?
"This method requires an HTTP POST request. For file uploads, a multipart POST method is required."

Posts: 7
Registered: Dec 19, 2008

A multi-part post is certainly more specific. In such a case, I would assume the api key and other parameters are the first part, and the second part (or attachment) would be the file contents. I'm also assuming the parameters part would be sent as Content-Type text/plain and file contents would be sent as Content-Type audio/mpeg, and that no special encoding is required. Such an attachment wouldn't generally be split into a name/value pair, so I won't be setting a value for the file parameter, just tossing up the audio file as an attachment and hoping the server grabs it as such.

Benny Hill taught us never to assume...I'd hate to try variations of these assumptions until I guessed correctly. If I could get the text of a sample POST for your server, I'd happily figure out how to generate it in the programming languages of choice...heck, I'll even post a perl module or php class if I can get this working...

Thank You again

Posts: 713
Registered: Sep 08, 2008

Vanoden: The upload post has certainly been a confusing part of the API. You are not the first to have trouble - so clearly it is something we need to figure out how to make a bit easier.

I always learn best from examples - so perhaps we could provide some coding examples on how to do the post. Would a Python or Java code example help? (It looks like you maybe a perl or php fan, but generating those examples may take a bit longer since our perl and php programmers are a bit busy at the moment).

Paul

Posts: 713
Registered: Sep 08, 2008

Vanoden: It's a lucky day. Our ace PHP programmer, Adam, dug up some PHP code that he wrote last year to upload a file to the echonest API. The code example is here:

http://static.echonest.com/examples/analyze.php.zip

This code is a bit out of date in that it points to the old echo nest endpoint. I think that if you change the endpoint from "http://api.echonest.com/" to "http://developer.echonest.com/api/" you should be good to go. (Note that I haven't tested this example, but I think that should be the only change you'll need to make).

On my TO DO list is to provide more code examples like this (but to make sure they are tested and actually work).

Paul

Posts: 7
Registered: Dec 19, 2008

Thank you so much, Paul. This should give me what I need to wrap up my project. I will probably create a perl module from this and don't mind donating it to the cause if others would be interested

Posts: 713
Registered: Sep 08, 2008

Vanoden: A perl version would be fantastic! I look forward to your contribution. Thanks!

Paul

Posts: 4
Registered: Feb 20, 2009

Ok, I did create the following multipart request:

POST /api/upload HTTP/1.1 User-Agent: echonest_uploader Content-Type: multipart/form-data, boundary=Abc123 Host: developer.echonest.com Content-Length: 202628 Connection: close

--Abc123 content-disposition: form-data; name="api_key"

XXXXXXXXXXXXXXXXX --Abc123 content-disposition: form-data; name="version"

3 --Abc123 content-disposition: form-data; name="file"; filename="Test.mp3" Content-Type: audio/mpeg Content-Transfer-Encoding: binary

--Abc123

and I still have no luck :(

am I closer?, do you have a text sample template you can post here?

Thanks! Ivan.

Posts: 713
Registered: Sep 08, 2008

lifeisgreat:

Ah clearly we need to do a bit of a better job reporting errors. "Connection close' is not very helpful. Apologies. What programming language are you using? Adam dug up a few examples of the post in a few of the more common programming languages, so if you are not doing things in clojure or haskel, or fortress maybe we have some code that will help.

Paul

Posts: 4
Registered: Feb 20, 2009

Hi Paul, I will test without "Connection: close", and the language I am using is Objective-C

Thanks! Ivan.

Posts: 7
Registered: Dec 19, 2008

Ok, I read the RFC for multipart/form-data, which covers the general formatting. I reviewed the code for Analyze.php which is for an older version and seems to use different variables. I used the ideas provided by these to generate a number of requests. Still, all I get back is 'Server Error'.

If someone has made it work, could they simply post the text of their request as a sample, trimming out the file data? That way the programming language wouldn't matter...sadly with such a simple error response, I can't tell if I'm getting any closer...

Thank You

Posts: 90
Registered: Aug 29, 2008

Thanks to remix, particularly echonest.web.util.postMultipart(), I was able to hack together a sample call, and dump it to a string. All CRLFs here are of the "rn" type.

The mime type:
multipart/form-data; boundary=----------------------------9bab5c68ca11

The request:

Content-Disposition: form-data; name="api_key"

XXXXXX

Content-Disposition: form-data; name="version"

3

Content-Disposition: form-data; name="wait"

Y

Content-Disposition: form-data; name="file"; filename="filename"
Content-Type: application/octet-stream

[File data here]

[_Gosh, I really hope it makes it through the markdown formatting_)

Posts: 713
Registered: Sep 08, 2008

atl - thanks for the sample call dump ... but it looks like the markdown had its way with it. Could you email me the text and I'll post it somewhere so everyone can read it? Much appreciated. Paul@echonest.com.

Posts: 90
Registered: Aug 29, 2008

Hmm... does this work?

All CRLFs here are of the "\r\n" type.

Posts: 7
Registered: Dec 19, 2008

Ok, I got it working...fell back to an existing perl module and the rest is history. Unfortunately I was not able to build the request from scratch, but I'm confident I was doing something wrong and don't have time to figure out what at the moment. I offer instead some sample code for Perl users, maybe others can get what they need from it. Thanks to all for your input, now off to process the response.

!/usr/bin/perl -w

use strict; use HTTP::Request::Common; use LWP::UserAgent; use XML::Simple; use Data::Dumper;

User Parameters

my $key = 'XXXXXXXX'; my $uri = "http://developer.echonest.com/api/upload"; my $full_path = '/path/to/your/file.mp3';

Build and Send Request

my $ua = LWP::UserAgent->new; my $response = $ua->request( POST $uri, Content_Type => 'form-data', Content => [ api_key => $key, version => 3, wait => 'Y', file => [$full_path], ] );

Display Response in 'readable' form

print Dumper XMLin($response->content());

Posts: 713
Registered: Sep 08, 2008

Vanoden: Glad to hear that you got it working. Special thanks for providing some perl code too. I'm going to be setting up a code samples page soon - and I'll be adding this code.

Thanks much!

Paul

Posts: 4
Registered: Feb 20, 2009

Hi, Just in the mood of providing useful information in my case the problem was not that I used "Connection: close" HTTP's header, I used "Connection: keep-alive" and I still had the same problem, the real problem in my case was that I had a typo in the "Content-Type" header, which instead of saying"multipart/form-data; boundary=AaB03x" I was sending "multipart/form-data, boundary=AaB03x", yeah the problem was a "," instead of a ";".

Anyway now it works and is really really a cool WEB api guys, thanks! :)

Ivan.

Posts: 2
Registered: May 22, 2009

Hi, I'm new to the Echo Nest, and I'm also having trouble with file upload. The error message I receive is "unknown file format". Here's the full xml response:

<?xml version="1.0" encoding="UTF-8"?> 
<response version="3"><status><code>5</code><message>Invalid parameter: unknown file format</message></status>
<query><parameter name="api_key">xxxxxxxxxxx</parameter><parameter name="file">01GreenChimneys.mp3</parameter>
<parameter name="wait">N</parameter></query></response>

I've tried several different mp3 files with the same response, so it seems unlikely that the error is file-specific. Is this an error that could be caused by an incorrect multipart http POST?

Posts: 713
Registered: Sep 08, 2008

Martin:

Extreme apologies for the delayed reply - I think I must have forgotten to hit the 'post reply' button last week. I just noticed now that your question had not been replied to.

I suspect that the problem is caused by an incorrect multipart http post. It can be a bit tricky. What language are you using? - perhaps I can point you to a code sample or two.

Paul

Posts: 2
Registered: May 22, 2009

Thanks for the reply.

I'm using Python, and a code sample using Upload would be very helpful. I suspect I am doing something wrong with the file 'attachment'.

Reply to this Thread

You must log in to post a reply.