用于添加图像路径的Python脚本

时间:2018-02-28 22:58:09

标签: python python-3.x

我有以下脚本,其中我在TEST_IMAGE_PATHS中添加了图像的路径。我的输入是" test_images"夹。在" test_images"文件夹图像命名为image0,image1,image2等。

将test_images中的图像添加到路径的脚本是:

function submitForm(bucket, accessToken) {
  console.log("Fetching the file...");
  var name = 'testName';
  var uploadUrl = 'https://www.googleapis.com/upload/storage/v1/b/'+ bucket +'/o?uploadType=media&access_tokenn=' + accessToken +'&name=' + name;
  fetch(uploadUrl, {
    method: 'POST',
    body: 'body stuff'
  }).then(function(res) {
    console.log('Something did happen!'); // <<----- Message never displayed!
    console.log(res);
  }).catch(function(err) {
    console.error('Got error:', err);
  });
}

submitForm('12345', 'testing');

此脚本输出: enter image description here

如何修改此脚本:

  1. 如上所述,我可以输入任何类型的图像(不仅限于jpeg)。图像类型包括JPG,png,jpg等

  2. 图像不应该命名为image0,image1,image2,image3,image4,image5,image6等。它不应该仅限于此命名约定,而应该选择&#39; test_images&中的所有图像#39;夹

  3. 我提到How can I iterate over files in a given directory?。如建议的那样,此链接说明了如何引用文件夹中的文件并将其添加到路径中。我的问题与添加到路径后对文件进行的修改有关。我可以使用上面的脚本将文件添加到路径中。我需要附加多个图像扩展。到现有的路径

1 个答案:

答案 0 :(得分:0)

PATH_TO_TEST_IMAGES_DIR = 'test_images'
TEST_IMAGE_PATHS = []
for ext in ('*.png', '*.jpeg'):
    TEST_IMAGE_PATHS.extend(glob(join(PATH_TO_TEST_IMAGES_DIR, ext)))

解决问题