API를 통해 사진을 게시하는 방법은?

그래서 일단 시도해 봤습니다(속담으로 말하면, 젖은 국수를 던져서 어디에 붙어 보자는 식이었죠). 하지만 처음부터 좀 불안했고 @simon 님의 말씀이 맞습니다.

이상적으로는 플러그인이 모바일에서도 사용 가능해야 합니다. 하지만 당장 데스크톱 전용이 우리가 얻을 수 있는 전부라면, 그렇게 받아들일 것입니다.

물론 다른 해결책도 있을 수 있습니다: 모바일의 Obsidian Vault → 데스크톱으로 동기화 → CLI를 통해 Discourse에 업로드. 하지만 그것은 좀 복잡해 보입니다.

기본적으로 이상적인 상황은 Discourse 포럼이 Obsidian Vault를 대체하는 것입니다. 그러면 포럼을 선호하는 사용자는 포럼을 사용하고, Obsidian을 선호하는(또는 실제로 오프라인 솔루션이 필요한) 사용자는 Obsidian을 사용할 수 있습니다. 양방향 동기화가 어떻게 작동할지에 대해 이미 몇 가지 아이디어가 있습니다. 하지만 먼저 이미지/파일을 어떤 방식으로든 처리해야 한다고 생각합니다.

수정:

이것이 작동할 것이라고 꽤 확신하지만, 매개변수를 올바르게 설정하는 것 같습니다:

					try {
						const imgfile = await this.app.vault.readBinary(file);
						const boundary = genBoundary();
						const sBoundary = '--' + boundary + '\r\n';
						let body = '';
						body += `${sBoundary}Content-Disposition: form-data; name="type"\r\n\r\ncomposer\r\n`;
						body += `${sBoundary}Content-Disposition: form-data; name="synchronous"\r\n\r\ntrue\r\n`;
						body += `${sBoundary}Content-Disposition: form-data; name="files[]"; filename="${file.name}"\r\nContent-Type: image/jpg\r\n`;

						const eBoundary = '\r\n--' + boundary + '--\r\n';
						const bodyArray = new TextEncoder().encode(body);
						const endBoundaryArray = new TextEncoder().encode(eBoundary);

						const formDataArray = new Uint8Array(bodyArray.length + imgfile.byteLength + endBoundaryArray.length);
						formDataArray.set(bodyArray, 0);
						formDataArray.set(new Uint8Array(imgfile), bodyArray.length);
						formDataArray.set(endBoundaryArray, bodyArray.length + imgfile.byteLength);

						const url = `${this.settings.baseUrl}/uploads.json`;
						const headers = {
							"Api-Key": this.settings.apiKey,
							"Api-Username": this.settings.disUser,
							"Content-Type": `multipart/form-data; boundary=${boundary}`
						};

						const response = await requestUrl({
							url: url,
							method: "POST",
							body: formDataArray,
							throw: false,
							headers: headers,
						});

						if (response.status == 200) {
							const jsonResponse = response.json();
							console.log(`Upload Image jsonResponse: ${JSON.stringify(jsonResponse)}`);
							imageUrls.push(jsonResponse.url);
						} else {
							new NotifyUser(this.app, `Error uploading image: ${response.status}`).open();
							console.error(`Error uploading image: ${JSON.stringify(response.json)}`);
						}