diff options
author | Cho <cho@lindenlab.com> | 2013-06-05 23:52:34 +0100 |
---|---|---|
committer | Cho <cho@lindenlab.com> | 2013-06-05 23:52:34 +0100 |
commit | 4d162e1ec2cd716f40666056bb9e2710958e3360 (patch) | |
tree | 5250b598c6cf63f2e24800c2715398d4d7ab2bf8 /indra/newview/llwebprofile.cpp | |
parent | 1734cabbcc15411afa4bd52e370290d6fbc487ba (diff) |
added callback to post photo with actual image url
Diffstat (limited to 'indra/newview/llwebprofile.cpp')
-rwxr-xr-x | indra/newview/llwebprofile.cpp | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/indra/newview/llwebprofile.cpp b/indra/newview/llwebprofile.cpp index 641f338f2c..4bc4724753 100755 --- a/indra/newview/llwebprofile.cpp +++ b/indra/newview/llwebprofile.cpp @@ -62,8 +62,8 @@ class LLWebProfileResponders::ConfigResponder : public LLHTTPClient::Responder LOG_CLASS(LLWebProfileResponders::ConfigResponder); public: - ConfigResponder(LLPointer<LLImageFormatted> imagep) - : mImagep(imagep) + ConfigResponder(LLPointer<LLImageFormatted> imagep, const std::string& caption, LLWebProfile::image_url_callback_t cb) + : mImagep(imagep), mImageCaption(caption), mImageCallback(cb) { } @@ -113,11 +113,13 @@ public: // Do the actual image upload using the configuration. LL_DEBUGS("Snapshots") << "Got upload config, POSTing image to " << upload_url << ", config=[" << config << "]" << llendl; - LLWebProfile::post(mImagep, config, upload_url); + LLWebProfile::post(mImagep, config, upload_url, mImageCaption, mImageCallback); } private: LLPointer<LLImageFormatted> mImagep; + std::string mImageCaption; + LLWebProfile::image_url_callback_t mImageCallback; }; /////////////////////////////////////////////////////////////////////////////// @@ -127,6 +129,22 @@ class LLWebProfileResponders::PostImageRedirectResponder : public LLHTTPClient:: LOG_CLASS(LLWebProfileResponders::PostImageRedirectResponder); public: + PostImageRedirectResponder(const std::string& caption, LLWebProfile::image_url_callback_t cb) + : mImageCaption(caption), mImageCallback(cb) + { + } + + /*virtual*/ void completedHeader(U32 status, const std::string& reason, const LLSD& content) + { + if (status == 200) + { + std::string image_url = content.get("Location"); + llinfos << "Image uploaded to " << image_url << llendl; + if (!mImageCallback.empty() && !image_url.empty()) + mImageCallback(image_url, mImageCaption); + } + } + /*virtual*/ void completedRaw( U32 status, const std::string& reason, @@ -148,9 +166,10 @@ public: LL_DEBUGS("Snapshots") << "Uploading image succeeded. Response: [" << body << "]" << llendl; LLWebProfile::reportImageUploadStatus(true); } - + private: - LLPointer<LLImageFormatted> mImagep; + std::string mImageCaption; + LLWebProfile::image_url_callback_t mImageCallback; }; @@ -161,6 +180,11 @@ class LLWebProfileResponders::PostImageResponder : public LLHTTPClient::Responde LOG_CLASS(LLWebProfileResponders::PostImageResponder); public: + PostImageResponder(const std::string& caption, LLWebProfile::image_url_callback_t cb) + : mImageCaption(caption), mImageCallback(cb) + { + } + /*virtual*/ void completedHeader(U32 status, const std::string& reason, const LLSD& content) { // Viewer seems to fail to follow a 303 redirect on POST request @@ -172,7 +196,7 @@ public: headers["Cookie"] = LLWebProfile::getAuthCookie(); const std::string& redir_url = content["location"]; LL_DEBUGS("Snapshots") << "Got redirection URL: " << redir_url << llendl; - LLHTTPClient::get(redir_url, new LLWebProfileResponders::PostImageRedirectResponder, headers); + LLHTTPClient::get(redir_url, new LLWebProfileResponders::PostImageRedirectResponder(mImageCaption, mImageCallback), headers); } else { @@ -188,6 +212,10 @@ public: const LLIOPipe::buffer_ptr_t& buffer) { } + +private: + std::string mImageCaption; + LLWebProfile::image_url_callback_t mImageCallback; }; /////////////////////////////////////////////////////////////////////////////// @@ -197,7 +225,7 @@ std::string LLWebProfile::sAuthCookie; LLWebProfile::status_callback_t LLWebProfile::mStatusCallback; // static -void LLWebProfile::uploadImage(LLPointer<LLImageFormatted> image, const std::string& caption, bool add_location) +void LLWebProfile::uploadImage(LLPointer<LLImageFormatted> image, const std::string& caption, bool add_location, LLWebProfile::image_url_callback_t cb) { // Get upload configuration data. std::string config_url(getProfileURL(LLStringUtil::null) + "snapshots/s3_upload_config"); @@ -207,7 +235,7 @@ void LLWebProfile::uploadImage(LLPointer<LLImageFormatted> image, const std::str LL_DEBUGS("Snapshots") << "Requesting " << config_url << llendl; LLSD headers = LLViewerMedia::getHeaders(); headers["Cookie"] = getAuthCookie(); - LLHTTPClient::get(config_url, new LLWebProfileResponders::ConfigResponder(image), headers); + LLHTTPClient::get(config_url, new LLWebProfileResponders::ConfigResponder(image, caption, cb), headers); } // static @@ -218,7 +246,7 @@ void LLWebProfile::setAuthCookie(const std::string& cookie) } // static -void LLWebProfile::post(LLPointer<LLImageFormatted> image, const LLSD& config, const std::string& url) +void LLWebProfile::post(LLPointer<LLImageFormatted> image, const LLSD& config, const std::string& url, const std::string& caption, LLWebProfile::image_url_callback_t cb) { if (dynamic_cast<LLImagePNG*>(image.get()) == 0) { @@ -284,7 +312,7 @@ void LLWebProfile::post(LLPointer<LLImageFormatted> image, const LLSD& config, c memcpy(data, body.str().data(), size); // Send request, successful upload will trigger posting metadata. - LLHTTPClient::postRaw(url, data, size, new LLWebProfileResponders::PostImageResponder(), headers); + LLHTTPClient::postRaw(url, data, size, new LLWebProfileResponders::PostImageResponder(caption, cb), headers); } // static |