[TypeError: Network request failed] when testing on iOS simulator

I’ve recently started using cloudflare’s image api, here’s my code with react native.

const getUploadUrl = async () => {
    // 서버에서 Cloudflare Direct Creator Uploads URL을 가져오는 API 호출
    const response = await fetch(
      `https://api.cloudflare.com/client/v4/accounts/${accountId}/images/v2/direct_upload`,
      {
        method: "POST",
        headers: {
          Authorization: `Bearer ${apiKey}`,
        },
      });
    const data = await response.json();
    return data.result.uploadURL;
  };

 const uploadImage = async () => {
    images.map(async (item, index) => {
        let data = new FormData();
        data.append('file', {
            uri: item.uri,
            name: item.uri.split('/').pop(),
            type: mime.getType(item.uri)
        });

        const response = await fetch(uploadUrls[index].url, {
        method: 'POST',
        body: data,
        headers: {
            'Content-Type': 'multipart/form-data',
        },
        })
        .then((res) => {console.log(res)})
        .catch((err) => {console.log(err)})

It’s weirdly not working, cuz it works when I try at first few times, but soon it returns [TypeError: Network request failed] with same code.

I’ve tried to search same issue but I couldn’t find any.

This topic was automatically closed after 15 days. New replies are no longer allowed.