Drop Box

851 views
Skip to first unread message

Vikram Chhajer

unread,
Apr 13, 2020, 2:13:57 PM4/13/20
to Harbour Users
Hello Harbour Experts  

Does Any body have dropbox api prg to upload files to drop box  . if please share the prg 


Thanks
Vikram

poopall

unread,
Apr 14, 2020, 9:23:04 PM4/14/20
to Harbour Users
Why do you need an API, just copy "whatever" to a folder that is synced with dropbox

Vikram Chhajer

unread,
Apr 15, 2020, 7:59:08 AM4/15/20
to Harbour Users
Hello Poopall

Sir by uploading files thru api i want sharabale link to be import in our database and after that i can mail the shareable link to my clients . SO Clients can Check Pdf/Doucuments in link .


Thanks 
Vikram 

poopall

unread,
Apr 16, 2020, 11:52:55 PM4/16/20
to Harbour Users
Ok I understand why you may need that, we do a similar thing but we upload the data to a folder on our website, create a uuid for the pdf/document and email that document name and link to our clients

If you use a uuid for the document name its pretty hard to guess and read somebody else's document, maybe that would be a better solution for you

Vikram Chhajer

unread,
Apr 17, 2020, 2:08:08 AM4/17/20
to Harbour Users
Thank You Sir 

Poopall Can you give some example prg and guide me how to do this .  can i upload pdf file  directly from my application   and get the share link . please explain me thow to do .

Thank You 
Vikram

Carlos Murúa

unread,
Apr 19, 2020, 6:51:44 PM4/19/20
to Harbour Users
Hi, Vikram Chhajer

Create an Dropbox account.
Create app.
DropBox Api.


Obtain apropiate acces type.
Obtain the access coken and put in de code.

Then implement the api client.

The code attached only implements get_metadata, donwload and upload methods.

Greetings, Carlos Murúa.
dropbox_cli.prg

Vikram Chhajer

unread,
Apr 20, 2020, 12:21:44 AM4/20/20
to Harbour Users
Thank you  Sir 

But After compling getting some error  .Using Harbour 3.2  .  Sir Can we convert this language to english so can easliy understand the prg . 


Lines 169, Functions/Procedures 1
Generating C source output to '.hbmk\win\mingw\dropbox_cli.c'... Done.
hbmk2: Compiling...
hbmk2: Linking... main.exe
.hbmk/win/mingw/dropbox_cli.o:dropbox_cli.c:(.data+0x98): undefined reference to `HB_FUN_MSCARTEL'
collect2: ld returned 1 exit status
hbmk2[main]: Error: Running linker. 1
gcc.exe .hbmk/win/mingw/dropbox_cli.o .hbmk/win/mingw/_hbmkaut_dropbox_cli.o    -Wl,--nxcompat -Wl,--dynamicbase -mwindows -Wl,--start-group -lhbnf -lhbformat -lhbfoxpro -lxhb -lhbct -lhbtip -lhbfship -lhbxpp -lhbwin -lpng -lhbziparc -lhbmzip -lminizip -lhbhpdf -llibhpdf -lhbzebra -lhbextern -lhbdebug -lhbvm -lhbrtl -lhblang -lhbcpage -lgtcgi -lgtpca -lgtstd -lgtwin -lgtwvt -lgtgui -lhbrdd -lhbuddall -lhbusrrdd -lrddntx -lrddcdx -lrddnsx -lrddfpt -lhbrdd -lhbhsx -lhbsix -lhbmacro -lhbcplr -lhbpp -lhbcommon -lhbmainwin -lkernel32 -luser32 -lgdi32 -ladvapi32 -lws2_32 -liphlpapi -lwinspool -lcomctl32 -lcomdlg32 -lshell32 -luuid -lole32 -loleaut32 -lmpr -lwinmm -lmapi32 -limm32 -lmsimg32 -lwininet -lhbpcre -lhbzlib   -Wl,--end-group -omain.exe  -Lc:/hb32/lib/win/mingw

hbmk2: Error: Referenced, missing, but unknown function(s): MSCARTEL()



Thanks & Regard 
Vikram Chhajer

Carlos Murúa

unread,
Apr 20, 2020, 12:25:34 AM4/20/20
to harbou...@googlegroups.com
Change mscartel to alert

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to a topic in the Google Groups "Harbour Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/harbour-users/_6MSWoyrggs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/ebfe331d-149e-4029-b95f-2171aae9a4ee%40googlegroups.com.

Vikram Chhajer

unread,
Apr 20, 2020, 12:34:36 AM4/20/20
to Harbour Users
Thanks Sir  
After Changing  mscartel to alert prg complied but giving some runtime error  

method dropbox rest no encontrado.\

Thanks 
Vikram
Change mscartel to alert


Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to a topic in the Google Groups "Harbour Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/harbour-users/_6MSWoyrggs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to harbou...@googlegroups.com.

Vikram Chhajer

unread,
Apr 20, 2020, 4:44:11 AM4/20/20
to Harbour Users
Sir 
After Making some changes i started to upload the file to my dropbox a/c     


in cjson I mention    cJSON :=    '{"C:\TMP\PDF\EMAIL.PDF","mode": "add","autorename": true,"mute": false,"strict_conflict": false}'        
Email.pdf is from my local drive which i have to upload in dropbox  . and 
  


DROP BOX -API-ARG  IS 
oHttp:setRequestHeader( "Dropbox-API-Arg", '{ "path" "' + "PMCSURAT\CKF1907319" + '", "mode" : "add" }' )

PMCSURAT IS FOLDER IN MY DROPBOX WHERE I HAVE TO UPLOAD THE FILE CKF1907319  

    
AND GET THIS ERROR   :   Error in call to API function "files/upload": HTTP header "Dropbox-API-Arg": could not decode input as JSON



THIS IS MY CODE  


function main()
local oHTTP,cJSON,url
setmode(25,80)
  ctoken      :=     "eHiSS5jXq0AAAAAAAAAAduAlRf3zXNAV8zYWtJ12IXXXXXXXXXXXXXXXXXXXXXXX"
    cJSON       :=    '{\"C:\TMP\PDF\EMAIL.PDF","mode": "add","autorename": true,"mute": false,"strict_conflict": false}'
     // cJSON := '{"path"\cPath, "mode": "add","autorename": true,"mute": false,"strict_conflict": false,}'  
   

    oHTTP := CREATEOBJECT('Msxml2.ServerXMLHTTP.6.0')
oHTTP:OPEN("POST",  url , .F.)
oHttp:setRequestHeader( "Authorization", "Bearer " + ctoken )
oHttp:setRequestHeader( "Dropbox-API-Arg", '{ "path" "' + "PMCSURAT\CKF1907319" + '", "mode" : "add" }' )
// oHttp:setRequestHeader( "Dropbox-API-Arg", '{ "path": "' + cPath + '", "mode" : "add" }' )
    oHttp:setRequestHeader( "Content-type", "application/octet-stream" )
    oHttp:SEND( cJSON )

IF oHTTP:status != 200
? oHTTP:responseText
hb_memowrit("response.txt",oHTTP:responseText)
? "Error"
ELSE
? oHTTP:responseText
         hb_memowrit("response.txt",oHTTP:responseText)
      ENDIF
wt = inkey(0)
return
 


SIR PLEASE HELP ME TO RESOLVE THIS ISSUE  . 

THANK YOU & REGARD 
VIKRAM 

Claudio H

unread,
Apr 20, 2020, 4:48:59 PM4/20/20
to Harbour Users
Vikram

cJSON       :=    '{\"C:\TMP\PDF\EMAIL.PDF","mode": "add","autorename": true,"mute": false,"strict_conflict": false}' 

is an invalid json, please verify the syntax, probably "path": missing at the beginning...

Try
cJSON := '{"path": "C:\TMP\PDF\EMAIL.PDF","mode": "add","autorename": true,"mute": false,"strict_conflict": false}' 

Regards
Claudio H

Message has been deleted

Carlos Murúa

unread,
Apr 20, 2020, 6:56:24 PM4/20/20
to Harbour Users
Try this !
 
FUNCTION uploadPdf()

    LOCAL bError, cPdfFile, oHttp, cResource_URL, cResource, cPath , cFileName, nLen, ;
    cResponse, accessToken, nHandler, cChar, bAll, cAll

    # xcommand TRY => bError := errorBlock( {|oErr| break( oErr ) } ) ;;
        BEGIN SEQUENCE

    # xcommand CATCH [<!oErr!>] => errorBlock( bError ) ;;
        RECOVER[ USING < oErr > ] <- oErr->;;
        ErrorBlock( bError )

    SetMode( 2580 )
    Clear Screen

    * folder name
    cPath := ''

    * file name.
    cPdfFile = 'myharu.pdf'
    
    * Open a file for low-level access
    IF ( nHandler := FOpen( cPath + cPdfFile ) ) == -1
        ? 'Error de apertura de fichero:' + STR( FError() )
        RETURN .F.
    ENDIF

    * Get the length of the file by moving the pointer to the end.
    nLen := FSeek( nHandler, 02 )
    
    * Reserve the space in the variable (indispensable).
    cAll := Space( nLen )
    
    * Move the file pointer to the beginning.
    Fseek( nHandler, 0 )

    * Read the file in cAll to the end.
    IF FREAD( nHandler, @cAll, nLen ) != nLen
        ? 'Error de lectura en ' + cPdfFile + Str( FError() )
        FClose( nHandler )
        RETURN .F.
    ENDIF

    * Close file.
    FClose( nHandler )

    bAll := ''
    FOR EACH cChar IN cAll
        IF Asc( cChar ) < 32
            bAll += I2Bin( Asc( cChar ) )
        ELSE
            bAll += cChar
        ENDIF
    NEXT
    
    oHttp  := Win_OleCreateObject( 'MSXML2.XMLHTTP.6.0' )

    IF Empty( oHttp )
        ? 'Could no create object oHttp.'
        ? 'Se cancela el programa.'
        ? 'Proceso cancelado.'
        RETURN .F.
    ENDIF

    cResource := 'uploadIva'
    accessToken := 'your_access_token'

    TRY
        cPath := '/' + cPdfFile
        oHttp:OPEN( "POST", cResource_URL, .F. )
        oHttp:setRequestHeader( "Authorization""Bearer " + accessToken )
        oHttp:setRequestHeader( "Dropbox-API-Arg"'{ "path": "' + cPath + '", "mode" : "overwrite" }' )
        oHttp:setRequestHeader( "Content-type""application/octet-stream" )
        oHttp:SEND( bAll )

    CATCH
        ? '*** ERROR ***'
        ? 'Controle la conexión a internet e intente de nuevo.'
        ? 'Proceso cancelado.'
        RETURN .F.
    
    END

    ? 'Getting response from appName repository. . .'
    
    * Connectivity error with the Web Service.
    IF oHttp:Status <> 200
        ? '*** ERROR ***'
        ? 'oHttp:Status = ' + AllTrim( Str( oHttp:Status ) )
        ? oHttp:StatusText + ' Process canceled.'
        oHttp := NIL
        RELEASE oHttp
        RETURN .F.
    ENDIF

    * I save Dropbox's reply.
    cResponse := oHttp:ResponseText

    * Name of the file according to the resource with pdf extension.
    cFileName := cPath + '\' + cResource

    * I save the answer in a file, to be able to consult it.
    MemoWrit( cFileName, cResponse )

    oHttp := NIL
    RELEASE oHttp

    ? 'The pdf file has been uploaded to the repository.'

RETURN .T.

Carlos Murúa

unread,
Apr 21, 2020, 2:24:02 AM4/21/20
to Harbour Users
In oyur code change:
oHttp:setRequestHeader( "Dropbox-API-Arg", '{ "path" : "' + 'PMCSURAT/CKF1907319' + '", "mode" : "add" }' )

Vikram Chhajer

unread,
Apr 21, 2020, 3:49:46 AM4/21/20
to Harbour Users
Thank You Sir

It Upload the File but After Uploading the file  the pdf have no content in it .    check this link file is complety empty  .
I can't understand this issue .

Vikram

Alain Aupeix

unread,
Apr 21, 2020, 4:05:12 AM4/21/20
to harbou...@googlegroups.com, Vikram Chhajer
Le 21/04/2020 à 09:49, Vikram Chhajer a écrit :
Thank You Sir

It Upload the File but After Uploading the file  the pdf have no content in it .    check this link file is complety empty  .
I can't understand this issue .

It's not empty, but its structure seems to be bad (under Linux):

An error occurs when opening this document. The file is damaged, and can't be repared.

It seems to be an acrobat 1.6 file.

Make a try with a simple text file ...


A+
--

Alain Aupeix
Sites web : JujuLand | Pissobi-Lacassagne | Gadel
X.ubuntu 16.04 [ H.arbour 3.2.0dev (r2020-02-24 15:33) | Hw.gui 2.22-4 (r2817) | G.ramps 5.0.1


Anupam

unread,
Apr 27, 2020, 5:01:35 AM4/27/20
to Harbour Users
Hi Carlos

Nice code to upload file to dropbox....but this work only with text file I try to upload pdf file this increase the file size and not display any data in the uploaded file on dropbox. 

what is wrong with this code...

I try with curl---

curl -X POST https://content.dropboxapi.com/2/files/upload --header "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxx"  --header "Dropbox-API-Arg: {\"path\": \"/Homework/test.pdf\",\"mode\": \"add\",\"autorename\": true,\"mute\": false,\"strict_conflict\": false}"  --header "Content-Type: application/octet-stream"  --data-binary @test.pdf

this is working ... 

where is wrong to post pdf file data with MSXML2.XMLHTTP.6.0 object.


Best Regards,

Anupam

Carlos Murúa

unread,
Apr 28, 2020, 6:59:52 PM4/28/20
to Harbour Users
Thanks Anupam !!!
I will implement curl.

Best Regards, Carlos Murua.

Vikram Chhajer

unread,
Apr 30, 2020, 10:54:34 PM4/30/20
to Harbour Users
Hello Sir 

Same Issue Facing , Please Help us to Upload file to Dropbox  . 

Thanks 

Vikram

Vikram Chhajer

unread,
May 8, 2020, 8:51:54 AM5/8/20
to Harbour Users
Hello Sir

Have You Implemented In Curl Becasue same issue i am also facing same proble m .  uploading file to dropbox but file contains shows empty in dropbox  . Please help to solve the issue . Already using prg as you provided . 


THanks 
Vikram

Vikram Chhajer

unread,
Jan 14, 2021, 12:23:43 PM1/14/21
to Harbour Users
Good Evening Sir 
HAve You Develoved the above code in curl . If  Then please shre the code.


Thanks 
Vikram

Vikram Chhajer

unread,
Jan 14, 2021, 12:25:54 PM1/14/21
to Harbour Users
Mr Poopall 
Can You Share Code of uuid  . how to upload files to  our website and share with client . Trying For Almost 1 year not getting success . 
Thanks 
Vikram

Reply all
Reply to author
Forward
0 new messages