I am using an third party uploader called Plupload and I wish to pass a selected image to a WebAPI method but I just cant seem to figure out how.
on the front end I Post a file object
uploader.bind('FileUploaded', function (up, file) {
data = { name: file.name, id: file.id, size: file.size, key: path };
$.ajax({
url: sf.getServiceRoot('mysite') + "upload/getS3Client",
type: "POST",
data: data,
beforeSend: sf.setModuleHeaders
}).done(function (response, status) {
alert(response);
}).fail(function (xhr, result, status) {
alert("error: " + result);
});
});
on the back end I receive the file object but I don't know what to do with it...
there is a MVC code snippet out there that I tried to use but apparently Web API does not support Request.Files[0] so I am lost. this is the snippet
HttpPostedFileBase file = Request.Files[0];
if (file.ContentLength > 0) // accept the file
{
string accessKey = "XXXXXXXXXXX";
string secretKey = "122334XXXXXXXXXX";
AmazonS3 client;
using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKey, secretKey))
{
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName("mealtik")
.WithCannedACL(S3CannedACL.PublicRead)
.WithKey("meals/test.jpg").InputStream = file.InputStream;
S3Response response = client.PutObject(request);
}
}
my method looks like this..its in flux right now.
public HttpResponseMessage getS3Client(file submitted)
{
HttpRequestMessage request = this.Request;
string accessKey = "xxxx";
string secretKey = "xxxx";
AmazonS3 client;
using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKey, secretKey ))
{
MemoryStream ms = new MemoryStream();
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName("Dev");
.WithKey("drop/" + submitted.name).InputStream = file.InputStream;
S3Response response = client.PutObject(request);
}
return Request.CreateResponse(HttpStatusCode.OK, "Success");
}
to sum it up. I am passing the file object to my method and trying to push it up to amazon s3 the stated MVC method work as it would seem but the same does not apply for Web API.
How might I do this?