- Home /
Uploading files to dropbox account programmatically
hi , my game is using dropbox api to sync files between many users , the problem is , all the api functions(downloading,creating folder,delete,move,getfiles) work perfectly except upload function , i took the source code and tested it in a whole new console application in visual studio and all function worked fine even upload, but unity dosn`t let me to do that instead it throws a web exception
"WebException: The remote server returned an error: (403) Forbidden. System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data)"
if think the problem is in (web requests logic) ,i think unity may be overriding (my request by another one , i don`t know ) the code for upload function is like this
public Dropbox.Api.FileSystemInfo UploadFile2(string root, string path, string file)
{
var uri = new Uri(new Uri(DropboxRestApi.ApiContentServer),
String.Format("files_put/{0}/{1}",
root, UpperCaseUrlEncode(path)));
var oauth = new OAuth();
var requestUri = oauth.SignRequest(uri, _consumerKey, _consumerSecret,accessToken,"POST");
var request = (HttpWebRequest)WebRequest.Create(requestUri);
request.Method = WebRequestMethods.Http.Post;
request.KeepAlive = true;
request.Timeout = 1000 * 60*60;
byte[] buffer;
using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
{
int length = (int)fileStream.Length;
buffer = new byte[length];
fileStream.Read(buffer, 0, length);
}
request.ContentLength = buffer.Length;
using (var requestStream = request.GetRequestStream())
{
requestStream.Write(buffer, 0, buffer.Length);
}
var response = request.GetResponse();
var reader = new StreamReader(response.GetResponseStream());
var json = reader.ReadToEnd();
return ParseJson<Dropbox.Api.FileSystemInfo>(json);
}
NOTE: i added this line System.Net.ServicePointManager.ServerCertificateValidationCallback = Helper.Validator; Helper.Validator simply return true all time so i can validate all server certification
Your answer
![](https://koobas.hobune.stream/wayback/20220613082153im_/https://answers.unity.com/themes/thub/images/avi.jpg)