그래서 S3 스토리지를 사용하여 다른 방법을 시도해 보았습니다. 여기의 설명을 따라 AWS S3 버킷을 설정했습니다. 제 설정은 다음과 같습니다:
그리고 제 코드는 다음과 같습니다:
async uploadExternalImage(imageReferences: string[]): Promise<string[]> {
const imageUrls: string[] = [];
for (const ref of imageReferences) {
const filePath = this.app.metadataCache.getFirstLinkpathDest(ref, this.activeFile.name)?.path;
if (filePath) {
const file = this.app.vault.getAbstractFileByPath(filePath) as TFile;
if (file) {
try {
const url = `${this.settings.baseUrl}/uploads/generate-presigned-put.json`;
//const imgfile = await this.app.vault.readBinary(file);
const img = {
type: "composer",
file_name: file.name,
file_size: file.stat.size,
}
console.log(JSON.stringify(img));
const headers = {
"Content-Type": "application/json",
"Api-Key": this.settings.apiKey,
"Api-Username": this.settings.disUser,
};
const response = await requestUrl({
url: url,
method: "POST",
body: JSON.stringify(img),
throw: false,
headers: headers
})
console.log(response.json)
} catch (error) {
console.error(`Error uploading: ${error}`);
//console.log(response.json)
}
} else {
console.error('error')
}
} else {
console.error('error')
}
}
return imageUrls;
}
현재는 실제로 파일을 업로드하지 않고 있으므로 작동하지 않는다는 것을 깨달았습니다. 문서에서 읽은 바로는, type, file_name, file_size를 포함하는 json 객체를 보내야 합니다. 그러면 API가 실제 파일 전송에 사용할 키와 url을 반환해야 합니다. 하지만 이 시점에서 다음과 같은 오류가 발생합니다:
{
"errors": [
"The requested URL or resource could not be found."
],
"error_type": "not_found"
}
[
"The requested URL or resource could not be found."
]
API 키에 권한이 있는지 확인해 보았지만, 권한은 있습니다. 그래도 새로 만들었고, 전역 키도 만들었습니다. 하지만 아무것도 작동하지 않습니다. 동일한 오류 코드가 나옵니다. 제가 무엇을 잘못하고 있나요?
수정: 여기 img 객체가 있습니다:
{"type":"composer","file_name":"face2.jpg","file_size":17342}
