Francesco Barreca
Francesco Barreca

Reputation: 281

Creation of image using apps script "send to drive"

Hi all i'm using send To Drive apps script.

Now if a e-mail that i receive contains a image as attachment, that image is stored in the folder that i specified but i can't see the preview as soon as i try to open it.

Instead if i upload manually the image in Google Drive i can see the preview.

I noticed that the urls of the images created from apps script have longer id than of the others image uploaded manually.

Example of image id that i cannot see (created by apps script):

https://docs.google.com/a/xxxx.com/file/d/0B1G2PrcwzsrzMS02MGEzNjBkOS01YjAyLTRhYTktODFkNS1kNzU5NmIzYWEyNDE/edit

Example of image id that i can see (uploaded manually)

https://docs.google.com/a/xxxx.com/file/d/0B1G2PrcwzsrzMG5kVDZuUGlqRWc/edit

How i can solve this problem modifying the script??

Thank you in advance

var threads = GmailApp.getUserLabelByName(gLabel).getThreads(0, 5);

  var folder  = DocsList.getFolder(gFolder);

  for (var x=0; x<threads.length; x++) {

    var messages = threads[x].getMessages();

    for (var y=0; y<messages.length; y++) {

      var att = messages[y].getAttachments();


      for (var z=0; z<att.length; z++) {
        try {

        Logger.log(att[z].getContentType());

          var file = folder.createFile(att[z]);
          Utilities.sleep(1000);
        }
        catch (e) {
          GmailApp.sendEmail(
            Session.getActiveUser().getUserLoginId(), 
            "Error: " + e.message
          );
        }
      }       
    }    
    GmailApp.getUserLabelByName(gLabel)
      .removeFromThread(threads[x]);
  }

Upvotes: 0

Views: 783

Answers (1)

nsmarko
nsmarko

Reputation: 11

I think this may be related to issue 1239

I can reproduce this within DocList using the createFile and copy method:

  //Using uploaded jpeg as source
    var doc =  DocsList.getFileById(id)
        DocsList.copy(doc,"test1");

The copy will load with no preview available

Upvotes: 1

Related Questions