We have an implementation of saving data in the "History" of Contacts, and we use the HttpWebRequest method like this POST. However, now every time we try to upload a file into the History email it returns this Error: 'The remote server returned an error: (400) Incorrect Request.'.
private static bool TransferFile(Guid fileRecordId, string columnName, byte[] file) {
log.Debug("[START] Transfer file");
try {
string requestUri = ServerUriUsr + "ActivityFileCollection(guid'" + fileRecordId.ToString() + "')/" + columnName;
HttpWebRequest request = RequestHelper.BuildRequest(requestUri, HttpMethod.Put);
request.Accept = "application/octet-stream,application/json;odata=verbose";
request.ContentType = "multipart/form-data;boundary=+++++";
// Recording the xml message to the request stream.
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(file, 0, file.Length);
}
// Receiving a response from the service regarding the operation implementation result.
using (WebResponse response = request.GetResponse())
{
if (((HttpWebResponse)response).StatusCode == HttpStatusCode.Created)
{
// Processing the operation implementation result.
response.Close();
log.Debug("[END] Transfer file (Successful)");
return true;
}
}
}
catch (WebException ex) {
if (ex.Response is null)
log.Error($"TransferFile function error: {ex.Message}");
else
log.Error($"TransferFile function error: {new StreamReader(ex.Response.GetResponseStream()).ReadToEnd()}");
throw;
}
catch (Exception ex) {
log.Error($"TransferFile function error: {ex.Message}");
throw;
}
return false;
}
The problem only occurs when I try to upload a .docx or .xlsx file