|
| 1 | +--- |
| 2 | +title: Entity Files |
| 3 | +description: Adjunta y expone archivos asociados a entidades, con almacenamiento opcional en S3 |
| 4 | +--- |
| 5 | + |
| 6 | +import { dynamiaToolsVersion } from '../../../../../astro.config.mjs'; |
| 7 | + |
| 8 | +## Que hace esta extension |
| 9 | + |
| 10 | +Entity Files permite adjuntar archivos a entidades JPA y almacenar el contenido binario en: |
| 11 | + |
| 12 | +- disco local (por defecto), o |
| 13 | +- AWS S3 (modulo opcional). |
| 14 | + |
| 15 | +Tambien incluye acciones UI para gestionar archivos desde vistas CRUD. |
| 16 | + |
| 17 | +## Maven |
| 18 | + |
| 19 | +<pre><code className="language-xml">{`<dependency> |
| 20 | + <groupId>tools.dynamia.modules</groupId> |
| 21 | + <artifactId>tools.dynamia.modules.entityfiles</artifactId> |
| 22 | + <version>${dynamiaToolsVersion}</version> |
| 23 | +</dependency> |
| 24 | +
|
| 25 | +<dependency> |
| 26 | + <groupId>tools.dynamia.modules</groupId> |
| 27 | + <artifactId>tools.dynamia.modules.entityfiles.ui</artifactId> |
| 28 | + <version>${dynamiaToolsVersion}</version> |
| 29 | +</dependency> |
| 30 | +
|
| 31 | +<dependency> |
| 32 | + <groupId>tools.dynamia.modules</groupId> |
| 33 | + <artifactId>tools.dynamia.modules.entityfiles.s3</artifactId> |
| 34 | + <version>${dynamiaToolsVersion}</version> |
| 35 | +</dependency>`}</code></pre> |
| 36 | + |
| 37 | +## Gradle |
| 38 | + |
| 39 | +<pre><code className="language-groovy">{`implementation 'tools.dynamia.modules:tools.dynamia.modules.entityfiles:${dynamiaToolsVersion}' |
| 40 | +implementation 'tools.dynamia.modules:tools.dynamia.modules.entityfiles.ui:${dynamiaToolsVersion}' |
| 41 | +implementation 'tools.dynamia.modules:tools.dynamia.modules.entityfiles.s3:${dynamiaToolsVersion}'`}</code></pre> |
| 42 | + |
| 43 | +## Paquete frontend |
| 44 | + |
| 45 | +```bash |
| 46 | +pnpm add @dynamia-tools/files-sdk @dynamia-tools/sdk |
| 47 | +``` |
| 48 | + |
| 49 | +```typescript |
| 50 | +import { DynamiaClient } from '@dynamia-tools/sdk'; |
| 51 | +import { FilesApi } from '@dynamia-tools/files-sdk'; |
| 52 | + |
| 53 | +const client = new DynamiaClient({ baseUrl: import.meta.env.VITE_API_URL, token: '...' }); |
| 54 | +const files = new FilesApi(client.http); |
| 55 | + |
| 56 | +const archivo = await files.download('factura.pdf', 'uuid-aqui'); |
| 57 | +const url = files.getUrl('images/logo.png', 'uuid-aqui'); |
| 58 | +``` |
| 59 | + |
| 60 | +## Ejemplo de uso en Java |
| 61 | + |
| 62 | +```java |
| 63 | +import jakarta.persistence.Entity; |
| 64 | +import jakarta.persistence.OneToOne; |
| 65 | +import tools.dynamia.modules.entityfile.domain.EntityFile; |
| 66 | + |
| 67 | +@Entity |
| 68 | +public class Person { |
| 69 | + |
| 70 | + @OneToOne |
| 71 | + private EntityFile photo; |
| 72 | + |
| 73 | + @OneToOne |
| 74 | + private EntityFile cover; |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +```java |
| 79 | +import java.io.File; |
| 80 | +import org.springframework.beans.factory.annotation.Autowired; |
| 81 | +import org.springframework.stereotype.Component; |
| 82 | +import tools.dynamia.modules.entityfile.UploadFileInfo; |
| 83 | +import tools.dynamia.modules.entityfile.service.EntityFileService; |
| 84 | + |
| 85 | +@Component |
| 86 | +public class PersonFilesService { |
| 87 | + |
| 88 | + @Autowired |
| 89 | + private EntityFileService entityFileService; |
| 90 | + |
| 91 | + public void attachPhoto(File file, Person person) { |
| 92 | + var info = new UploadFileInfo(file); |
| 93 | + var photo = entityFileService.createEntityFile(info, person); |
| 94 | + person.setPhoto(photo); |
| 95 | + } |
| 96 | +} |
| 97 | +``` |
| 98 | + |
0 commit comments