PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 21 → large (resumable) file upload using onedrive/graph api
large (resumable) file upload using onedrive/graph api
Débuté par Mike Stewart, 20 fév. 2017 12:57 - 2 réponses
//hostimage.webdev.info/avatars/default.gif
Posté le 20 février 2017 - 12:57
I have managed to get all of the required communications for the graph api to do most things but the large file upload I am struggling with this one.


This is the example that I am trying to recreate for each portion of the file

PUT https://tenant-my.sharepoint.com/alkjl1kjklna
Content-Length: 26
Content-Range: bytes 0-25/128

<bytes 0-25 of the file>

here is the code I am using to try and achieve this

sCompl is string ="N"
nSoFar is int =0
nPiece is int =1
//splitting the file into sections which are divisible by 320kiB
nSixBit is 8byte int = 1966080
nAttempts is int = 1
nTot is 8byte int = fSize(sAd)
nFiles is int = fSplit(sAd,nSixBit,"splitFile")
i = 1
WHILE sCompl="N" AND nAttempts<=5
sF is string = i
IF i>9 THEN
sF="splitFile.0"+sF
ELSE
sF="splitFile.00"+sF
END
HTTPCreateForm("piecemeal")
sTot is string = fSize(sF)
nThisPieceSize is int = fSize(sF)
//HTTPAddParameter("piecemeal","Content-Length",sTot)
sContRan is string = "bytes%20"+nSoFar+"-"+(nSoFar+nThisPieceSize-1)+"/"+nTot
//HTTPAddParameter("piecemeal","Content-Range",sContRan)
bufThisOne is Buffer = fLoadBuffer(sF)
sBuf is ANSI string = bufThisOne
sFinal is ANSI string = StringBuild("Content-Length: %1"+CR+"Content-Range: %2"+CR+CR+"%3",sTot,sContRan,sBuf)
sUploadURL=sUploadURL+"&Content-Length="+sTot+"&Content-Range="+sContRan
IF HTTPSendForm("piecemeal",sUploadURL,httpPut,"Mozilla/4.0 (compatible; MSIE 4.01 - Windows CE)",sBuf,"text/plain") = True THEN
bufResHTTP = HTTPGetResult(httpResult)
IF IniOSMode() = True OR IniOSSimulatorMode() = True OR IniOSEmulatorMode() = True THEN
IF StringCount(bufResHTTP, “ISO-8859-1, IgnoreCase) = 0 THEN
sHTTPRes = UTF8ToString(bufResHTTP)
ELSE
sHTTPRes = AnsiToUnicode(bufResHTTP)
END
ELSE IF InAndroidMode() = True OR InAndroidSimulatorMode() = True OR InAndroidEmulatorMode() = True
// result in Android
sHTTPRes = UTF8ToString(bufResHTTP)
END
sHead = (HTTPGetResult(httpHeader))
// EDT_NoName1=sHTTPRes
IF Contains(sHead,"HTTP/1.1 202 Accepted")=True THEN
nSoFar=nSoFar+nThisPieceSize
nAttempts=1
IF i=nFiles THEN
sCompl="Y"
END
ELSE
nAttempts++
END

ELSE
Error(ErrorInfo(errMessage))
END
i++
END


When I try to put the parameters in via httpAddParameter then I get 400 errors (badly formed request)
When I create a single string with all of the parameters (including the file piece) then the sendForm is failing.

Any suggestions are greatly welcomed.

Mike
//hostimage.webdev.info/avatars/default.gif
Posté le 21 février 2017 - 10:01
Well progress is being made using the following couple of lines

// using split file I create the necessary fragments
nFiles is int = fSplit(sAd,nSixBit,"splitFile")

// These are then attached to the form using httpAddFile
sFinal is ANSI string = StringBuild("Content-Length: %1"+CR+"Content-Range: %2"+CR+CR,sTot,sContRan)
HTTPAddFile("piecemeal",sFinal,sF,"application/x-www-form-urlencoded")

This is now producing a file of the right size and name at the other end but this file (a moviefile for testing purposes) doesn't play. I am looking to transfer zip files that will contain images as well as data. So obviously the integrity of that data is vital.

I am now looking at whether there are missing pieces where the data did not quite all transfer or if the 'format' of the data transfer (plain/text... urencoded etc makes any difference.

Again though any suggestions welcome
//hostimage.webdev.info/avatars/default.gif
Posté le 23 février 2017 - 10:00
Add the file buffer as a parameter with no heading (instead of using httpaddfile)

Send the form using the application/xml to sort out the boundaries.


Done