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

upload dossier

parent f21341e6
No related branches found
No related tags found
No related merge requests found
...@@ -158,12 +158,12 @@ curl -X POST -H "X-Resource-Type: folder" -H "Authorization: Bearer valid-token- ...@@ -158,12 +158,12 @@ curl -X POST -H "X-Resource-Type: folder" -H "Authorization: Bearer valid-token-
- créer fichier : - créer fichier :
```shell ```shell
curl -X POST -H "X-Resource-Type: file" -H "Authorization: Bearer valid-token-1" -H "X-FTP-User: user" -H "X-FTP-Pass: password" http://localhost:8080/ftps/mon-ftp/dossier/fichier curl -X POST -H "X-Resource-Type: file" -H "Authorization: Bearer valid-token-1" -H "X-FTP-User: user" -H "X-FTP-Pass: password" http://localhost:8080/ftps/mon-ftp/fichier
``` ```
- renommer : - renommer :
```shell ```shell
curl -X PUT -H "Authorization: Bearer valid-token-1" -H "X-FTP-User: user" -H "X-FTP-Pass: password" -H "Content-Type: text/plain" -d "nouveau_nom" http://localhost:8080/ftps/mon-ftp/dossier/rename curl -X PUT -H "Authorization: Bearer valid-token-1" -H "X-FTP-User: user" -H "X-FTP-Pass: password" -H "Content-Type: text/plain" -d "nouveau_nom" http://localhost:8080/ftps/mon-ftp/rename/fichier
``` ```
- supprimer dossier/fichier : - supprimer dossier/fichier :
......
...@@ -225,7 +225,7 @@ public class FTPResource { ...@@ -225,7 +225,7 @@ public class FTPResource {
} }
@PUT @PUT
@Path("/{alias}/{path: .+}/rename") @Path("/{alias}/rename/{path: .+}")
@Consumes(MediaType.TEXT_PLAIN) @Consumes(MediaType.TEXT_PLAIN)
public Response renameResource( public Response renameResource(
@PathParam("alias") String alias, @PathParam("alias") String alias,
......
...@@ -279,9 +279,11 @@ public class FTPService { ...@@ -279,9 +279,11 @@ public class FTPService {
while ((entry = zis.getNextEntry()) != null) { while ((entry = zis.getNextEntry()) != null) {
String entryName = entry.getName(); String entryName = entry.getName();
String fullPath = constructPath(targetPath, entryName); String fullPath = constructPath(targetPath, entryName);
System.out.println("[DEBUG] Traitement entrée: " + entry.getName() if (fullPath == null) {
+ " → " + fullPath); zis.closeEntry();
continue; // Ignorer l'entrée racine
}
System.out.println("[DEBUG] Traitement entrée: " + entry.getName() + " → " + fullPath);
if (entry.isDirectory()) { if (entry.isDirectory()) {
createDirectories(ftp, fullPath); createDirectories(ftp, fullPath);
} else { } else {
...@@ -300,11 +302,20 @@ public class FTPService { ...@@ -300,11 +302,20 @@ public class FTPService {
private String constructPath(String basePath, String entryPath) { private String constructPath(String basePath, String entryPath) {
// Ignorer le premier segment du chemin (dossier racine du ZIP) // Ignorer le premier segment du chemin (dossier racine du ZIP)
String[] parts = entryPath.split("/"); String[] parts = entryPath.split("/");
if (parts.length > 1) { List<String> partsList = new ArrayList<>();
String normalizedEntry = String.join("/", Arrays.copyOfRange(parts, 1, parts.length)); for (String part : parts) {
return basePath.isEmpty() ? normalizedEntry : basePath + "/" + normalizedEntry; if (!part.isEmpty()) {
partsList.add(part);
}
} }
return entryPath; // Cas où l'entrée est déjà à la racine if (!partsList.isEmpty()) {
partsList.remove(0); // Retirer le premier segment (racine du ZIP)
}
String normalizedEntry = String.join("/", partsList);
if (normalizedEntry.isEmpty()) {
return null; // Indique une entrée de répertoire racine à ignorer
}
return basePath.isEmpty() ? normalizedEntry : basePath + "/" + normalizedEntry;
} }
private void createParentDirectories(FTPClient ftp, String filePath) throws IOException { private void createParentDirectories(FTPClient ftp, String filePath) throws IOException {
...@@ -342,12 +353,10 @@ public class FTPService { ...@@ -342,12 +353,10 @@ public class FTPService {
private void uploadFileEntry(FTPClient ftp, String path, InputStream is) private void uploadFileEntry(FTPClient ftp, String path, InputStream is)
throws IOException, FTPException { throws IOException, FTPException {
// Supprimer URLDecoder.decode() ! String fileName = path.contains("/") ? path.substring(path.lastIndexOf('/') + 1) : path;
String decodedPath = path;
try (InputStream bais = is) { try (InputStream bais = is) {
if (!ftp.storeFile(decodedPath, bais)) { if (!ftp.storeFile(fileName, bais)) {
throw new FTPException("Échec upload: " + decodedPath, 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