Helop with Box Integration into Web application

New post



  • mwiller

    Hi  —if you're replacing Crocodoc, you should look into Box View, which should provide roughly equivalent functionality.  There are a few guides available in the developer documentation that I linked to to help you get started!

    Comment actions Permalink
  • gwmubiru

    Hi Mwiller,


    Thank you very much for the response. I have read this for 2 days now but still I have failed to get started.  I have looked at uploading a file; When I looked the parameters (left hand side) and the sample CURL in the black section, the parameters do not match. CURL has more parameters than those explained in the parameters (left hand side). So I end up confused on what to use where and when.


    How do I get started?



    Comment actions Permalink
  • gwmubiru

    I have tried using CURL but I do not receive any out put....see below


    $attributes = array('name'=>time().'.docx','parent'=>array('id'=>0));    
        $params = array('attributes' => json_encode($attributes), 'file' => "@".realpath('http://veritracker.com/staging/box/test.docx'));
        $headers = array("Authorization: Bearer ".'MY-APP-TOKEN');    
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://upload.box.com/api/2.0/files/content');
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        $data = curl_exec($ch);
        $server_output = curl_exec ($ch);
            //$serv_object = json_decode($server_output);


    Comment actions Permalink
  • mwiller

     I'm not very familiar with PHP's curl wrapper, but when I tried your code on my machine I got the following:


    php > $attributes = array('name'=>time().'.docx','parent'=>array('id'=>0));
    php > $params = array('attributes' => json_encode($attributes), 'file' => "@".realpath('http://veritracker.com/staging/box/test.docx'));
    php > var_dump($params);
    php shell code:1:
    array(2) {
      'attributes' =>
      string(44) "{"name":"1520887153.docx","parent":{"id":0}}"
      'file' =>
      string(1) "@"

    It appears that maybe realpath() isn't doing the right thing when used with a URL — can you verify that the parameters are all what you expect them to be?

    Comment actions Permalink
  • gwmubiru

    When I try I get boolean (false) and I am wondering why. Can you send me a CURL which works fine and I will see how to use it in PHP


    php > $path_to_doc = '/root/var/www/vhosts/superyachtos/superyachtos.com/uploads/user_1/***number removed for privacy***1.doc';
    php > $attributes = array('name'=>time().'.docx','parent'=>array('id'=>0));
    php > $params = array('attributes' => json_encode($attributes), 'file' => '@'.$path_to_doc.'/test.docx','created_at' => date(DATE_ATOM), 'modified_at' => date(DATE_ATOM));
    php > $headers = array("Authorization: Bearer ".'jxdxcw09m58h0d6z3twb50qsy3zb870l','Content-Type:multipart/form-data');
    php > $ch = curl_init();
    php > curl_setopt($ch, CURLOPT_URL, 'https://upload.box.com/api/2.0/files/2/content');
    php > curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    php > curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    php > curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    php > curl_setopt($ch, CURLOPT_POST, true);
    php > curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    php > $data = curl_exec($ch);
    php > var_dump($data);
    php > curl_close($ch);

    Comment actions Permalink
  • mwiller

    Here's a curl command that worked for me and the verbose output from curl:



    14:36 $ curl -vvv https://upload.box.com/api/2.0/files/content -H "Authorization: Bearer MY_ACCESS_TOKEN" -F attributes='{"name":"ai.pdf","parent":{"id":"0"}}' -F file=@/Users/mwiller/Desktop/ai.pdf 
    *   Trying
    * TCP_NODELAY set
    * Connected to upload.box.com ( port 443 (#0)
    * ALPN, offering http/1.1
    * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
    * successfully set certificate verify locations:
    *   CAfile: /usr/local/etc/openssl/cert.pem
      CApath: /usr/local/etc/openssl/certs
    * TLSv1.2 (OUT), TLS header, Certificate Status (22):
    * TLSv1.2 (OUT), TLS handshake, Client hello (1):
    * TLSv1.2 (IN), TLS handshake, Server hello (2):
    * NPN, negotiated HTTP1.1
    * TLSv1.2 (IN), TLS handshake, Certificate (11):
    * TLSv1.2 (IN), TLS handshake, Server key exchange (12):
    * TLSv1.2 (IN), TLS handshake, Server finished (14):
    * TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
    * TLSv1.2 (OUT), TLS change cipher, Client hello (1):
    * TLSv1.2 (OUT), TLS handshake, Unknown (67):
    * TLSv1.2 (OUT), TLS handshake, Finished (20):
    * TLSv1.2 (IN), TLS change cipher, Client hello (1):
    * TLSv1.2 (IN), TLS handshake, Finished (20):
    * SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
    * ALPN, server did not agree to a protocol
    * Server certificate:
    *  subject: C=US; ST=California; L=Redwood City; O=Box, Inc.; CN=*.box.com
    *  start date: Feb  7 00:00:00 2018 GMT
    *  expire date: Nov 28 12:00:00 2020 GMT
    *  subjectAltName: host "upload.box.com" matched cert's "*.box.com"
    *  issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=GeoTrust RSA CA 2018
    *  SSL certificate verify ok.
    > POST /api/2.0/files/content HTTP/1.1
    > Host: upload.box.com
    > User-Agent: curl/7.58.0
    > Accept: */*
    > Authorization: Bearer rwB0BDUbWZk4unK5ieFc5jD0tHiS18Zr
    > Content-Length: 49904941
    > Content-Type: multipart/form-data; boundary=------------------------ba519f0d74c4553e
    > Expect: 100-continue
    * Done waiting for 100-continue
    < HTTP/1.1 100 Continue
    < Date: Tue, 13 Mar 2018 23:07:53 GMT
    < Server: Server
    < HTTP/1.1 201 Created
    < Date: Tue, 13 Mar 2018 23:07:45 GMT
    < Content-Type: application/json
    < Cache-Control: no-cache, no-store
    < Strict-Transport-Security: max-age=31536000
    < Vary: Accept-Encoding
    < Content-Length: 1050
    < Age: 24
    < Connection: keep-alive
    * Connection #0 to host upload.box.com left intact
    {"total_count":1,"entries":[{REDACTED FILE INFORMATION]}

    One thing I notice is that curl is sending an "Expect: 100-continue" header by default — that may be related to your issue in some way.  I found some information about this sort of issue on StackOverflow that may be helpful for you as well.


    Comment actions Permalink

Please sign in to leave a comment.