كيفية نشر الصور عبر API؟

لذلك، فكرت في تجربة نهج مختلف باستخدام تخزين 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;
	}

الآن، أدرك أن هذا لن يعمل حاليًا لأنني لا أقوم فعليًا بتحميل الملف بعد. بناءً على ما قرأته في المستندات، سأرسل كائن JSON يحتوي على النوع واسم الملف وحجم الملف. يجب أن يرد واجهة برمجة التطبيقات بمفتاح وعنوان URL لنقلهما للملف الفعلي. ولكن في هذه المرحلة، أحصل على الخطأ التالي:

{
    "errors": [
        "The requested URL or resource could not be found."
    ],
    "error_type": "not_found"
}

[
“The requested URL or resource could not be found.”
]

لقد نظرت في مفتاح واجهة برمجة التطبيقات الخاص بي للتأكد من أنه يمتلك الأذونات، وهو كذلك. لكنني أنشأت واحدًا جديدًا على أي حال. وواحدًا عامًا. لا يعمل أي منها. نفس رمز الخطأ. ما الخطأ الذي أرتكبه؟

تعديل، هذا هو كائن الصورة:

{"type":"composer","file_name":"face2.jpg","file_size":17342}