PROFESSIONAL NEWSGROUPS
WINDEV
,
WEBDEV
and
WINDEV Mobile
Home
|
Recent messages
|
Connect
|
Sign out
|
English
Home
→
WINDEV Mobile 2024
→
large (resumable) file upload using onedrive/graph api
large (resumable) file upload using onedrive/graph api
Started by Mike Stewart, Feb., 20 2017 12:57 PM - 2 replies
Connect yourself…
Mike Stewart
#1
Posted on February, 20 2017 - 12:57 PM
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
s
Compl
is string
=
"N"
n
SoFar
is int
=
0
n
Piece
is int
=
1
//splitting the file into sections which are divisible by 320kiB
n
SixBit
is
8
byte int
=
1966080
n
Attempts
is int
=
1
n
Tot
is
8
byte int
=
fSize
(
s
Ad
)
n
Files
is int
=
fSplit
(
s
Ad
,
n
SixBit
,
"splitFile"
)
i
=
1
WHILE
s
Compl
=
"N"
AND
n
Attempts
<
=
5
s
F
is string
=
i
IF
i
>
9
THEN
s
F
=
"splitFile.0"
+
s
F
ELSE
s
F
=
"splitFile.00"
+
s
F
END
HTTPCreateForm
(
"piecemeal"
)
s
Tot
is
string
=
fSize
(
s
F
)
n
ThisPieceSize
is int
=
fSize
(
s
F
)
//HTTPAddParameter("piecemeal","Content-Length",sTot)
s
ContRan
is string
=
"bytes%20"
+
n
SoFar
+
"-"
+
(
n
SoFar
+
n
ThisPieceSize
-
1
)
+
"/"
+
n
Tot
//HTTPAddParameter("piecemeal","Content-Range",sContRan)
buf
ThisOne
is
Buffer
=
fLoadBuffer
(
s
F
)
s
Buf
is ANSI string
=
buf
ThisOne
s
Final
is ANSI string
=
StringBuild
(
"Content-Length: %1"
+
CR
+
"Content-Range: %2"
+
CR
+
CR
+
"%3"
,
s
Tot
,
s
ContRan
,
s
Buf
)
s
UploadURL
=
s
UploadURL
+
"&Content-Length="
+
s
Tot
+
"&Content-Range="
+
s
ContRan
IF
HTTPSendForm
(
"piecemeal"
,
s
UploadURL
,
httpPut
,
"Mozilla/4.0 (compatible; MSIE 4.01 - Windows CE)"
,
s
Buf
,
"text/plain"
) =
True
THEN
buf
ResHTTP
=
HTTPGetResult
(
httpResult
)
IF
IniOSMode
(
) =
True
OR
IniOSSimulatorMode
(
) =
True
OR
IniOSEmulatorMode
(
) =
True
THEN
IF
StringCount
(
buf
ResHTTP
, “
ISO
-
8859
-
1
”
,
IgnoreCase
) =
0
THEN
s
HTTPRes
=
UTF8ToString
(
buf
ResHTTP
)
ELSE
s
HTTPRes
=
AnsiToUnicode
(
buf
ResHTTP
)
END
ELSE IF
InAndroidMode
(
) =
True
OR
InAndroidSimulatorMode
(
) =
True
OR
InAndroidEmulatorMode
(
) =
True
// result in Android
s
HTTPRes
=
UTF8ToString
(
buf
ResHTTP
)
END
s
Head
= (
HTTPGetResult
(
httpHeader
)
)
//
EDT_NoName1=sHTTPRes
IF
Contains
(
s
Head
,
"HTTP/1.1 202 Accepted"
)
=
True
THEN
n
SoFar
=
n
SoFar
+
n
ThisPieceSize
n
Attempts
=
1
IF
i
=
n
Files
THEN
s
Compl
=
"Y"
END
ELSE
n
Attempts
+
+
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
Report
0
0
Mike Stewart
#2
Posted on February, 21 2017 - 10:01 AM
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
Report
0
0
Mike Stewart
#3
Posted on February, 23 2017 - 10:00 AM
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
Report
0
0
→ Go back to WINDEV Mobile 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (earlier versions)
Français
English
Español
Portuguesa
Close this window
Search type
Only topics
All the messages
Search period
Any time
Past hour
Past 24 hours
Past week
Past month
Past year
Cancel
Preview of your message
Adding an image
Import an image from a URL
Send an image from a file of your disk
Drop a file or click "Browse..."
or
Cancel
0%
WLanguage
SQL
XML, HTML
JAVA, Javascript
Text