So I thought I’d try a different approach by using the S3 storage. I followed the instructions here to setup an AWS S3 bucket. Here are my settings:
And here is my code:
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;
}
Now, I realize this currently won’t work because I’m not actually uploading the file yet. From what I read in the docs, I would send a json object containing the type, file_name, and file_size. The api should reply with a key and a url for me to use for the actual file transfer. But at this point, I’m getting the following error:
{
"errors": [
"The requested URL or resource could not be found."
],
"error_type": "not_found"
}
[
"The requested URL or resource could not be found."
]
I looked into my API key to make sure it had permissions, it does. But I created a new one anyways. And a global one. None are working. Same error code. What am I doing wrong?
Edit, here’s the img object:
{"type":"composer","file_name":"face2.jpg","file_size":17342}