[ADÐ] DESCARGA DE ARCHIVOS DRIVE API

parent 1d09c733
...@@ -6,6 +6,7 @@ import java.util.Collections; ...@@ -6,6 +6,7 @@ import java.util.Collections;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
...@@ -69,8 +70,8 @@ public class DriveService implements IDriveService { ...@@ -69,8 +70,8 @@ public class DriveService implements IDriveService {
try { try {
File file = googleConfig.getDrive().files().get(file_id).execute(); File file = googleConfig.getDrive().files().get(file_id).execute();
InputStream inputStream = googleConfig.getDrive().files().get(file_id).executeMediaAsInputStream(); 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]); String uudi = java.util.UUID.randomUUID().toString();
tempFile.deleteOnExit(); java.io.File tempFile = new java.io.File(System.getProperty("java.io.tmpdir") + "/" + uudi + "." + file.getName().split("\\.")[1]);
try (FileOutputStream fos = new FileOutputStream(tempFile)) { try (FileOutputStream fos = new FileOutputStream(tempFile)) {
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
int bytesRead; int bytesRead;
...@@ -78,8 +79,10 @@ public class DriveService implements IDriveService { ...@@ -78,8 +79,10 @@ public class DriveService implements IDriveService {
fos.write(buffer, 0, bytesRead); fos.write(buffer, 0, bytesRead);
} }
} }
if (base64) { if (base64) {
String base64String = commonUtils.fileToBase64(tempFile); String base64String = commonUtils.fileToBase64(tempFile);
tempFile.delete(); // Eliminación inmediata en modo Base64
return ResponseEntity.ok().body( return ResponseEntity.ok().body(
new JSONObject() new JSONObject()
.put("base64", base64String) .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