FORUMS PROFESSIONNELS
WINDEV
,
WEBDEV
et
WINDEV Mobile
Accueil
|
Messages récents
|
Connexion
|
Déconnexion
|
Français
Accueil
→
WINDEV Mobile 2024
→
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
Connectez-vous…
Mike Stewart
#1
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
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
Signaler
0
0
Mike Stewart
#2
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
Signaler
0
0
Mike Stewart
#3
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
Signaler
0
0
→ Revenir à WINDEV Mobile 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (précédentes versions)
Français
English
Español
Portuguesa
Fermer cette fenêtre
Type de recherche
Uniquement les sujets
Tous les messages
Période de recherche
Date indifférente
Moins d'une heure
Moins de 24 heures
Moins d'une semaine
Moins d'un mois
Moins d'un an
Annuler
Aperçu de votre message
Ajouter une image
Importer une image depuis une URL
Envoyer une image depuis un fichier de votre disque
Déposez ici un fichier ou cliquez sur "Parcourir..."
ou
Annuler
0%
WLangage
SQL
XML, HTML
JAVA, Javascript
Texte