[ADÐ] DESCARGA DE ARCHIVOS DRIVE API

parent 1d09c733
......@@ -6,6 +6,7 @@ import java.util.Collections;
import lombok.AllArgsConstructor;
import org.json.JSONObject;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
......@@ -69,8 +70,8 @@ public class DriveService implements IDriveService {
try {
File file = googleConfig.getDrive().files().get(file_id).execute();
InputStream inputStream = googleConfig.getDrive().files().get(file_id).executeMediaAsInputStream();
java.io.File tempFile = new java.io.File(System.getProperty("java.io.tmpdir") + "/temp." + file.getName().split("\\.")[1]);
tempFile.deleteOnExit();
String uudi = java.util.UUID.randomUUID().toString();
java.io.File tempFile = new java.io.File(System.getProperty("java.io.tmpdir") + "/" + uudi + "." + file.getName().split("\\.")[1]);
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
byte[] buffer = new byte[1024];
int bytesRead;
......@@ -78,8 +79,10 @@ public class DriveService implements IDriveService {
fos.write(buffer, 0, bytesRead);
}
}
if (base64) {
String base64String = commonUtils.fileToBase64(tempFile);
tempFile.delete(); // Eliminación inmediata en modo Base64
return ResponseEntity.ok().body(
new JSONObject()
.put("base64", base64String)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment