新しいBoxサポートサイトへようこそ。 変更点の詳細はこちらをご確認ください .

How to upload file?

新規投稿

コメント

6件のコメント

  • Murtza

    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. 

    0
    コメントアクション Permalink
  • Box Product Support

    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. 

    0
    コメントアクション Permalink
  • Murtza

    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. 

     

    0
    コメントアクション Permalink
  • Box Product Support

    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

     

     

    0
    コメントアクション Permalink
  • Box Product Support

    We currently have no license for the app user that we are testing with. Do you think this is the reason that the user is not able to upload file even if it has permissions?

    0
    コメントアクション Permalink
  • kattarp

    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.

    0
    コメントアクション Permalink

投稿コメントは受け付けていません。