I'm trying to upload a file with Keep2Share api
In the documentation are a Php Implementation, which are the following
$data = $this->getUploadFormData($parent_id, $preferred_node);
$curl = curl_init();
$postFields = $data['form_data'];
$postFields[$data['file_field']] = new CURLFile($file);
curl_setopt_array($curl, [
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $data['form_action'],
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postFields,
]);
$response = curl_exec($curl);
if ($this->verbose) {
echo '<<', $response, PHP_EOL;
}
return json_decode($response, true);
getUploadFormData
method return a json with the following data
status: [success]
status_code: [200,400]
form_action: string
file_field: string
form_data: [
params: string
signature: string
]
But i need to translate it to C#, i'm trying the following
//dat is a object with getUploadForm data
var dat = await this.GetUploadFormData();
HttpContent stringContent = new StringContent(dat.form_data.signature);
HttpContent bytesContent = new ByteArrayContent(System.IO.File.ReadAllBytes(filename));
using (var client = new HttpClient())
using (var formData = new MultipartFormDataContent())
{
formData.Add(stringContent, "signature", "signature");
formData.Add(bytesContent, "file", "file");
var response = await client.PostAsync(dat.form_action, formData);
using (var reader = new StreamReader(await response.Content.ReadAsStreamAsync()))
{
Console.WriteLine(await reader.ReadToEndAsync());
}
return await response.Content.ReadAsStreamAsync();
}
But i'm getting
{"name":"Bad Request","message":"Wrong signature. IP 1**.58.*54.213","code":0,"status":400}
I'm almost sure that my problem is that I'm not passing the signature parameter as it should be
is that the case?
what i'm doing wrong?
Thanks!
EDIT
An example of getUploadFormData object should be
"status":"success",
"code":200,
"form_action":"http://file-api-27.keep2share.cc:8000/upload",
"file_field":"file",
"form_data":{
"ajax":true,
"_params":null,
"signature":"2eda59a25137a78ef05513c60182cebe9972d9d1b80d9e643e0a8104dcdf42f59cfbc76680c7caf2d93e090c74ebdcf19da664c53e9da14992d604469a634887"
}