@@ -64,20 +64,28 @@ class ObjectStoreStorage extends StorageBase {
6464 async save ( file , targetDir ) {
6565 // NOTE: the base implementation of `getTargetDir` returns the format this.storagePath/YYYY/MM
6666 const storagePath = targetDir || this . getTargetDir ( this . storagePath ) ;
67+ console . log ( 'Saving file to Object Store:' , file ) ;
68+ console . log ( 'Target directory:' , targetDir ) ;
69+ console . log ( 'Storage Path' , storagePath ) ;
6770
6871 // NOTE: getUniqueFileName is deprecated in v1.1.1 of ghost-storage-base, it is recommended to use getUniqueSecureFilePath instead.
6972 // See: https://github.com/TryGhost/Ghost-Storage-Base/blob/c78655b1cd54c93b53327bc8e1cf3123c085ebd2/BaseStorage.js#L131
7073 // However, calling that method results in files being corrupted in Object Store.
7174 //
7275 // TODO: Figure out why getUniqueSecureFilePath corrupts files and switch to using it.
73- const fileName = await this . getUniqueFileName ( file , storagePath ) ;
76+ const fileName = await this . getUniqueSecureFilePath ( file , storagePath ) ;
7477
7578 const objectKey = fileName . replace ( / \\ / g, '/' ) ;
7679
80+ // The file object contains metadata but not the actual file content
81+ // We need to read the file from the filesystem path to get the content
82+ const fs = require ( 'fs' ) . promises ;
83+ const fileContent = await fs . readFile ( file . path ) ;
84+
7785 const command = new PutObjectCommand ( {
7886 Bucket : this . bucket ,
7987 Key : objectKey ,
80- Body : file . contents || file . path ,
88+ Body : fileContent ,
8189 ContentType : file . type
8290 } ) ;
8391
0 commit comments