How to upload file?
I have created a folder using BOX App User and I am using BOX Java SDK.
Now I would like to upload file to that folder with the SDK. Can someone point me to right direction please. Have you guys tried uploading file with Java SDK using App User right?
Please help me out here, I am stuck with this a week!!!
Thanks!
-T
-
Here is the documentation for the Upload File method in the Java SDK. In this method, you specify which folder you want to upload the file to.
-
Is there a Python package or library for Uploading files to a box folder.
I am planning to upload large amounts of files to box and would need a way to do it without without logging in through a browser to my box account but using a python script to login to my account and upload my files through this script.
Please let me know what are the Authentication methods needed for box.
-
Here's the link to our Python SDK.
You can use an Enterprise access token and the As-User header to upload files to your account using the Python SDK.
If the As-User header functionality is not enabled in your account, please file a ticket to request this.
-
Hi Murtza, thanks for the reseponse.
I am actually following the documentation and the example you provided. First I created a folder with the appuser token and then tried to upload a file to the folder as shown in the java example.
However, the response is 403 error code. I can retreive the folder full info and inspect the permission coresponding to that user. The user has the following permissions on the folder (which it owns): [CAN_DOWNLOAD, CAN_UPLOAD, CAN_RENAME, CAN_DELETE, CAN_SHARE, CAN_INVITE_COLLABORATOR, CAN_SET_SHARE_ACCESS].
The code is as follows (Scala):
val boxApi = BoxConfig.getUserAPI(file.ownerId) val folder = new BoxFolder(boxApi, file.folderId) println(folder.getInfo(BoxFolder.ALL_FIELDS :_*).getPermissions) val inputStream = fileUtil.getInputStream(file.filename) val fileInfo = folder.uploadFile(inputStream, file.filename)
Now I can't seem to figure out what is wrong. Can you please direct me here?
Thanks!
-T
-
Hi, try this
public void UploadFile(string fileUrl)
{
var authenticator = new TokenProvider(clientId, clientSecret);
var oAuthToken = authenticator.RefreshAccessToken(refreshToken);
accessToken = oAuthToken.AccessToken;
BoxTool.Properties.Settings.Default.accessToken = oAuthToken.AccessToken;
BoxTool.Properties.Settings.Default.refreshToken = oAuthToken.RefreshToken;
//var boxManager = new BoxManager(accessToken);
string[] pathSplit = fileUrl.Split('\\');
byte[] byteArray = System.IO.File.ReadAllBytes(fileUrl);var client = new RestClient("https://upload.box.com/api/2.0");
var request = new RestRequest("/files/content", Method.POST);
request.AddParameter("parent_id", Folder.Root); //Give whatever the Folder Id, where u wanna drop a file.
request.AddParameter("content_created_at", "20**removed**T10:55:**removed**:00");
request.AddHeader("Authorization", "Bearer " + accessToken);
request.AddFile("name", byteArray, pathSplit[pathSplit.Length - 1]);var responses = client.Execute(request);
var content = responses.Content;}
Note: Be sure that RestClient dll is added to reference.
Post is closed for comments.
Comments
6 comments