Bonjour,

Dans un de mes codes de fileupload, j'utilise un mode chunk pour les fichiers volumineux. Mais voilà à la fin, j'ai bien le volume du fichier mais il est inutilisable.

Voici mon code
Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
 
 Private Sub Uploadfile(ByVal context As HttpContext)
 
        context.Response.ContentType = "text/plain"
        Dim r As New Generic.LinkedList(Of ViewDataUploadFilesResult)
        Dim js As New Script.Serialization.JavaScriptSerializer
 
        If context.Request.Files.Count >= 1 Then
 
            If Not System.IO.Directory.Exists(RootFolder) Then System.IO.Directory.CreateDirectory(RootFolder)
 
            Dim InfNav As HelperBrowser.InfoNavigateur = HelperBrowser.InfoBrowser
            Dim FileName As String = String.Empty
            Dim hpf As HttpPostedFile = Nothing
            Dim Range = context.Request.Headers.GetValues("Content-Range")
 
            'For i = 0 To context.Request.Files.Count - 1
            hpf = context.Request.Files.Item(0) 'i
 
            If InfNav.Name = HelperBrowser.IE Then
                Dim files As String() = hpf.FileName.Split(CChar("\\"))
                FileName = files(files.Length - 1)
            Else
                FileName = Path.GetFileName(hpf.FileName)
            End If
            Dim savedFileName As String = RootFolder & FileName
 
            Try
                'Fichier envoyé en 1 seul bloc
                'Vérif taille : sinon chunck
                If Range Is Nothing Then
 
                    If hpf.ContentLength <= CDbl(HelperParams.GetConfig(PARAM_UPL_JS_SIZE_MAX_FILE)) Then
 
                        If CDbl(hpf.ContentLength + CDbl(HelperFile.GetFolderSize(RootFolder))) <= HelperParams.GetConfig(PARAM_UPL_JS_SIZE_MAX) Then
                            hpf.SaveAs(savedFileName)
                            r.AddLast(New ViewDataUploadFilesResult(FileName, hpf.ContentLength, hpf.ContentType))
                        Else
                            r.AddLast(New ViewDataUploadFilesResult(FileName, MSG_ERR_SIZ_TOT))
                        End If
 
                    Else
                        r.AddLast(New ViewDataUploadFilesResult(FileName, MSG_ERR_FIL_SIZ_MAX))
                    End If
 
                Else
 
                    Using fs = New IO.FileStream(savedFileName, IO.FileMode.Append)
 
                        Dim PartFromRange As String() = Range(0).Split({" ", "-", "/"}, StringSplitOptions.RemoveEmptyEntries)
                        Dim Length As Long = CLng(PartFromRange(3))
                        Dim UploadedSize As Long = CLng(PartFromRange(1))
 
                        'Controles de la taille
                        If fs.Length = UploadedSize Then
                            'Ecriture
                            Dim buffer = New Byte(hpf.InputStream.Length - 1) {}
                            fs.Write(buffer, 0, buffer.Length)
 
                            Dim IsLast As Boolean = (CDbl(PartFromRange(2)) + 1 = Length) '+1 car range commençant à 0
                            If IsLast Then r.AddLast(New ViewDataUploadFilesResult(FileName, Length, hpf.ContentType))
                        Else
                            r.AddLast(New ViewDataUploadFilesResult(FileName, "Perte d'information lors du transfert du fichier."))
                        End If
 
                    End Using
 
                End If
 
                'Next
 
            Catch ex As Exception
                HelperJournal.WriteException(ex)
                r.AddLast(New ViewDataUploadFilesResult(FileName, ex.Message))
            End Try
 
        Else
            r.AddLast(New ViewDataUploadFilesResult(String.Empty, "Pas de fichier transmis!"))
        End If
 
        Dim uploadedFiles = New With {Key .files = r.ToArray}
        Dim jsonObj = js.Serialize(uploadedFiles)
        context.Response.Write(jsonObj.ToString)
 
    End Sub

Vous trouverez le reste du code ici. C'est un code source que j'ai mis à disposition.

J'ai ajouté
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
Dim buffer As Byte() = New Byte(hpf.InputStream.Length - 1) {}
 
                            Dim ess = System.Text.Encoding.Unicode.GetString(buffer)
et ess = ""
Donc normal que ça marche pas ... Comment puis -je savoir si mon context.Request.Files.Item(0) est bon?