LoginSignup
1
0

Qiitaに複数画像を同時にアップロード

Posted at
const image_urls = [
  'https://cors1.deno.dev/https://cdn.qiita.com/assets/public/image-qiitan_for_login_modal-014e085d3e40a240e3fe8d61b70b29a9.png',
  'https://cors1.deno.dev/https://blog.qiita.com/wp-content/uploads/2023/05/45e8009e-2099-0308-3579-5bfe6fcd61d9.png',
  'https://cors1.deno.dev/https://cdn.qiita.com/assets/public/push_notification/image-qiitan-572179a3bbde375850422ea48b2b6272.png',
]
const sleep = msec => new Promise(resolve => setTimeout(resolve, msec));

for await (const url of image_urls) {
  const temp1 = await fetch(url).then(r=>r.blob())
  const file = new File([temp1], Date.now() + '.png', {type: 'image/png'})

  const dataTransfer = new DataTransfer()
  dataTransfer.items.add(file)

  const pasteEvent = new ClipboardEvent('paste', {
    bubbles: true,
    cancelable: true,
    clipboardData: dataTransfer,
  })
  document.querySelector('.cm-content').dispatchEvent(pasteEvent)
  await sleep(500)
}

// TODO: によるアップロード実装

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0