フロントエンドからバックエンドに画像ファイルを送信する方法はありますか?フォームで選択した画像をクラウドクラウドプラットフォームにアップロードする必要があります。フロントエンドからバックエンドへの画像ファイルデータの送信
req.body
でファイル入力にアクセスすることは役に立たず、no such file or directory open
というエラーが表示されます。
私はenctype="multipart/form-data"
を追加し、私のバックエンドで、その後req.on('data', (data)=> {console.log(data.toString)})
とはcloudinaryにアップロードを実行しない場合、それは失敗し、私は次のエラーを与える:Error: Path must be a string without null bytes
これは私のフォームです:
<form method="post" action="/submitArticle" enctype="multipart/form-data">
<div class="file">
<label class="file-label">
<input class="file-input" type="file" name="image">
<span class="file-cta">
<span class="file-icon">
<i class="fa fa-upload"></i>
</span>
<span class="file-label">
Choose a file…
</span>
</span>
</label>
</div>
<div class="field">
<label class="title is-4">Title</label>
<div class="control">
<input class="input" name="title" type="text" placeholder="Give your story a title...">
</div>
</div>
<div class="field">
<label class="title is-4">Story</label>
<div class="control">
<textarea class="textarea" name="story" rows="7" placeholder="Tell your story here..."></textarea>
</div>
</div>
<div class="field is-grouped is-grouped-right">
<p class="control">
<input class="button is-primary" type="submit">
</input>
</p>
</div>
</form>
イメージデータをフロントエンドからバックエンドに送信する別の方法はありますか?前もって感謝します!!