Skip to content
Snippets Groups Projects
Commit 8d9fe4e3 authored by fabiovandewaeter's avatar fabiovandewaeter
Browse files

upload dossier

parent f557b7ed
Branches
No related tags found
No related merge requests found
...@@ -107,12 +107,12 @@ unzip dossier1.zip ...@@ -107,12 +107,12 @@ unzip dossier1.zip
curl -X PUT -H "Authorization: Bearer valid-token-1" -H "X-FTP-User: user" -H "X-FTP-Pass: password" --upload-file fichier2 http://localhost:8080/ftps/mon-ftp/fichier2 curl -X PUT -H "Authorization: Bearer valid-token-1" -H "X-FTP-User: user" -H "X-FTP-Pass: password" --upload-file fichier2 http://localhost:8080/ftps/mon-ftp/fichier2
``` ```
- upload dossier (ne fonctionne pas bien pour le moment je crois) : - upload dossier :
```shell ```shell
curl -X PUT -H "Authorization: Bearer valid-token-1" -H "X-FTP-User: user" -H "X-FTP-Pass: password" --upload-file dossier2.zip http://localhost:8080/ftps/mon-ftp/dossier2.zip zip -r dossier2.zip dossier2
curl -X POST -H "Authorization: Bearer valid-token-1" -H "X-FTP-User: user" -H "X-FTP-Pass: password" -H "Content-Type: application/octet-stream" --data-binary @dossier2.zip http://localhost:8080/ftps/mon-ftp/upload-dir/ curl -X POST -H "Authorization: Bearer valid-token-1" -H "X-FTP-User: user" -H "X-FTP-Pass: password" -H "Content-Type: application/octet-stream" --data-binary @dossier2.zip http://localhost:8080/ftps/mon-ftp/upload-dir/dossier2
``` ```
**Note comprise entre 12 et 13 si—en plus—le proxy FlopBox, permet de télécharger (download) et téléverser (upload) un gros fichier binaire (image, vidéo, etc.):** **Note comprise entre 12 et 13 si—en plus—le proxy FlopBox, permet de télécharger (download) et téléverser (upload) un gros fichier binaire (image, vidéo, etc.):**
......
...@@ -13,6 +13,7 @@ import java.util.zip.ZipInputStream; ...@@ -13,6 +13,7 @@ import java.util.zip.ZipInputStream;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.io.ByteArrayInputStream;
public class FTPService { public class FTPService {
...@@ -350,12 +351,22 @@ public class FTPService { ...@@ -350,12 +351,22 @@ public class FTPService {
} }
} }
private void uploadFileEntry(FTPClient ftp, String path, InputStream is) private void uploadFileEntry(FTPClient ftp, String path, ZipInputStream zis)
throws IOException, FTPException { throws IOException, FTPException {
String fileName = path.contains("/") ? path.substring(path.lastIndexOf('/') + 1) : path; String fileName = path.contains("/") ? path.substring(path.lastIndexOf('/') + 1) : path;
try (InputStream bais = is) {
if (!ftp.storeFile(fileName, bais)) { // Lire le contenu du fichier dans un tableau d'octets
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = zis.read(buffer)) != -1) {
baos.write(buffer, 0, bytesRead);
}
// Uploader le contenu depuis le tableau d'octets
try (InputStream bis = new ByteArrayInputStream(baos.toByteArray())) {
if (!ftp.storeFile(fileName, bis)) {
throw new FTPException("Échec upload: " + path, 500); throw new FTPException("Échec upload: " + path, 500);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment