Skip to content
Snippets Groups Projects
Commit 08ef748c authored by Rider Linden's avatar Rider Linden
Browse files

Added file upload interface to core HTTP utils.

parent 97033975
Branches
No related tags found
No related merge requests found
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "llsdjson.h" #include "llsdjson.h"
#include "llsdserialize.h" #include "llsdserialize.h"
#include "reader.h" #include "reader.h"
#include "llvfile.h"
#include "message.h" // for getting the port #include "message.h" // for getting the port
...@@ -621,6 +622,61 @@ LLSD HttpCoroutineAdapter::postRawAndYield(LLCoros::self & self, LLCore::HttpReq ...@@ -621,6 +622,61 @@ LLSD HttpCoroutineAdapter::postRawAndYield(LLCoros::self & self, LLCore::HttpReq
return postAndYield_(self, request, url, rawbody, options, headers, httpHandler); return postAndYield_(self, request, url, rawbody, options, headers, httpHandler);
} }
// *TODO: This functionality could be moved into the LLCore::Http library itself
// by having the CURL layer read the file directly.
LLSD HttpCoroutineAdapter::postFileAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request,
const std::string & url, std::string fileName,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
LLCore::BufferArray::ptr_t fileData(new LLCore::BufferArray, false);
// scoping for our streams so that they go away when we no longer need them.
{
LLCore::BufferArrayStream outs(fileData.get());
llifstream ins(fileName.c_str(), std::iostream::binary | std::iostream::out);
if (ins.is_open())
{
ins.seekg(0, std::ios::beg);
ins >> std::noskipws;
std::copy(std::istream_iterator<U8>(ins), std::istream_iterator<U8>(),
std::ostream_iterator<U8>(outs));
ins.close();
}
}
return postAndYield(self, request, url, fileData, options, headers);
}
// *TODO: This functionality could be moved into the LLCore::Http library itself
// by having the CURL layer read the file directly.
LLSD HttpCoroutineAdapter::postFileAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request,
const std::string & url, LLUUID assetId, LLAssetType::EType assetType,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
LLCore::BufferArray::ptr_t fileData(new LLCore::BufferArray, false);
// scoping for our streams so that they go away when we no longer need them.
{
LLCore::BufferArrayStream outs(fileData.get());
LLVFile vfile(gVFS, assetId, assetType, LLVFile::READ);
S32 fileSize = vfile.getSize();
U8* fileBuffer;
fileBuffer = new U8[fileSize];
vfile.read(fileBuffer, fileSize);
outs.write((char*)fileBuffer, fileSize);
delete[] fileBuffer;
}
return postAndYield(self, request, url, fileData, options, headers);
}
LLSD HttpCoroutineAdapter::postAndYield_(LLCoros::self & self, LLCore::HttpRequest::ptr_t &request, LLSD HttpCoroutineAdapter::postAndYield_(LLCoros::self & self, LLCore::HttpRequest::ptr_t &request,
const std::string & url, LLCore::BufferArray::ptr_t &rawbody, const std::string & url, LLCore::BufferArray::ptr_t &rawbody,
LLCore::HttpOptions::ptr_t &options, LLCore::HttpHeaders::ptr_t &headers, LLCore::HttpOptions::ptr_t &options, LLCore::HttpHeaders::ptr_t &headers,
......
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
#include "llevents.h" #include "llevents.h"
#include "llcoros.h" #include "llcoros.h"
#include "lleventcoro.h" #include "lleventcoro.h"
#include "llassettype.h"
#include "lluuid.h"
/// ///
/// The base llcorehttp library implements many HTTP idioms /// The base llcorehttp library implements many HTTP idioms
...@@ -355,6 +357,34 @@ class HttpCoroutineAdapter ...@@ -355,6 +357,34 @@ class HttpCoroutineAdapter
LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false), headers); LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false), headers);
} }
LLSD postFileAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request,
const std::string & url, std::string fileName,
LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false),
LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders(), false));
LLSD postFileAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t &request,
const std::string & url, std::string fileName,
LLCore::HttpHeaders::ptr_t &headers)
{
return postFileAndYield(self, request, url, fileName,
LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false), headers);
}
LLSD HttpCoroutineAdapter::postFileAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request,
const std::string & url, LLUUID assetId, LLAssetType::EType assetType,
LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false),
LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders(), false));
LLSD HttpCoroutineAdapter::postFileAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request,
const std::string & url, LLUUID assetId, LLAssetType::EType assetType,
LLCore::HttpHeaders::ptr_t &headers)
{
return postFileAndYield(self, request, url, assetId, assetType,
LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false), headers);
}
/// Execute a Put transaction on the supplied URL and yield execution of /// Execute a Put transaction on the supplied URL and yield execution of
/// the coroutine until a result is available. /// the coroutine until a result is available.
/// ///
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment