//static void KVFlickrRequest::uploadPhoto(const LLSD& args, LLImageFormatted *image, response_callback_t callback) { LLSD params(args); params["api_key"] = KV_FLICKR_API_KEY; params["api_sig"] = getSignatureForCall(params, false); // It would be nice if there was an easy way to do multipart form data. Oh well. std::string boundary = "------------" + LLUUID::generateNewID().asString(); std::ostringstream post_stream; post_stream << "--" << boundary; // Add all the parameters from LLSD to the query. for(LLSD::map_const_iterator itr = params.beginMap(); itr != params.endMap(); ++itr) { post_stream << "\r\nContent-Disposition: form-data; name=\"" << itr->first << "\""; post_stream << "\r\n\r\n" << itr->second.asString(); post_stream << "\r\n" << "--" << boundary; } // Headers for the photo post_stream << "\r\nContent-Disposition: form-data; name=\"photo\"; filename=\"snapshot." << image->getExtension() << "\""; post_stream << "\r\nContent-Type: "; // Apparently LLImageFormatted doesn't know what mimetype it has. if(image->getExtension() == "jpg") { post_stream << "image/jpeg"; } else if(image->getExtension() == "png") { post_stream << "image/png"; } else // This will (probably) only happen if someone decides to put the BMP entry back in the format selection floater. { // I wonder if Flickr would do the right thing. post_stream << "application/x-wtf"; LL_WARNS("FlickrAPI") << "Uploading unknown image type." << LL_ENDL; } post_stream << "\r\n\r\n"; // Now we build the postdata array, including the photo in the middle of it. // C memory operations abound! std::string post_str = post_stream.str(); size_t total_data_size = image->getDataSize() + post_str.length() + boundary.length() + 6; // + 6 = "\r\n" + "--" + "--" char* post_data = new char[total_data_size + 1]; memcpy(post_data, post_str.data(), post_str.length()); char* address = post_data + post_str.length(); memcpy(address, image->getData(), image->getDataSize()); address += image->getDataSize(); std::string post_tail = "\r\n--" + boundary + "--"; memcpy(address, post_tail.data(), post_tail.length()); address += post_tail.length(); llassert(address <= post_data + total_data_size /* After all that, check we didn't overrun */); // We have a post body! Now we can go about building the actual request... LLSD headers; headers["Content-Type"] = "multipart/form-data; boundary=" + boundary; LLHTTPClient::postRaw("http://api.flickr.com/services/upload/", (U8*)post_data, total_data_size, new KVFlickrUploadResponse(callback), headers); // The HTTP client takes ownership of our post_data array, // and will delete it when it's done. }
void KVFlickrRequest::request(const std::string& method, const LLSD& args, response_callback_t callback) { LLSD params(args); params["format"] = "json"; params["method"] = method; params["api_key"] = KV_FLICKR_API_KEY; params["nojsoncallback"] = 1; params["api_sig"] = getSignatureForCall(params, true); // This must be the last one set. LLHTTPClient::get("http://flickr.com/services/rest/", params, new KVFlickrResponse(callback)); }
void exoFlickr::signRequest(LLSD& params, std::string method, std::string url) { // Oauth junk params["oauth_consumer_key"] = EXO_FLICKR_API_KEY; std::string oauth_token = gSavedPerAccountSettings.getString("ExodusFlickrToken"); if(oauth_token.length()) { params["oauth_token"] = oauth_token; } params["oauth_signature_method"] = "HMAC-SHA1"; params["oauth_timestamp"] = (LLSD::Integer)time(NULL); params["oauth_nonce"] = ll_rand(); params["oauth_version"] = "1.0"; params["oauth_signature"] = getSignatureForCall(params, url, method); // This must be the last one set. }