Question

I want to write a function for uploading photos to flickr as http://www.flickr.com/services/api/upload.api.html. I wrote the following code:

val http = new Http with thread.Safety
val uploadEndPoint = :/("api.flickr.com") / "services" / "upload"

then I sign the method using dispatch

def signUploadRequest(userParams: Map[String, String], accessToken: Token, verifier: String): Map[String, String] = {
    var map = userParams
    map += "api_key" -> consumerKey
    sign("", uploadEndPoint.toString, userParams, consumer, Some(accessToken), Some(verifier), Some(OAuth.oob))
  }

Then I call the following method:

def sendUploadRequest(reqParms: Map[String, String]) = { http(uploadEndPoint.POST <:< reqParms as_str) }

but I got the following error:

<rsp stat="fail">
    <err code="100" msg="Invalid API Key (Key has invalid format)" />
</rsp>

I use the same procedure for requests and it works fine. What is the problem with the Post?

Thanks, Feras

Was it helpful?

Solution

I don't know this flickr api, but shouldn't the map pass as the request body ?

Another remark is that, they say that the photo can't be part of the signature (just in case the userParams contains its).

So, if you should use post's body instead of putting the map in the headers (which does <:<):

def sendUploadRequest(reqParms: Map[String, String]) = { http(uploadEndPoint << reqParms as_str) }

The << convert the request to post, using the given map as the payload. Note that using POST will set the Map body as empty.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top