public async upload()

in source/frontend/src/services/photo-service.ts [54:79]


  public async upload(photo: File): Promise<{ photoId: string }> {
    const { results } = await Client.get('api', `${this.resource}/upload_urls`, {
      queryStringParameters: {
        count: 1,
        type: 'search',
      },
    });
    if (!results || results.length === 0) {
      throw new Error('upload url is empty');
    }
    const uploadUrl = results[0];
    const uploaded = await fetch(uploadUrl.url, {
      method: 'PUT',
      body: photo,
      mode: 'cors',
      headers: {
        'Content-Type': '',
      },
    });
    if (!uploaded.ok) {
      throw new Error('failed to upload');
    }
    return {
      photoId: uploadUrl.id,
    };
  }