4
$\begingroup$

I have a zip file in the cloud but I can't seem to unzip it!

a = CreateArchive[FindFile["ExampleData/rose.gif"], 
   OverwriteTarget -> True];    
c = CloudPut[a, Permissions -> "Public"]    

I've tried things like this:

ExtractArchive[c, "/home/"]

What is the correct one-liner here?

$\endgroup$

2 Answers 2

5
$\begingroup$

This works for me:

a=CreateArchive[FindFile["ExampleData/rose.gif"],$TemporaryDirectory<>"test.zip"];
c=CopyFile[a,CloudObject[zipFile = "rose.zip",Permissions->"Public"],OverwriteTarget->True];
CloudEvaluate[ExtractArchive[zipFile,File["newRose"]]]
CloudEvaluate["LastModificationDate"/.FileInformation["newRose/rose.gif"]]
$\endgroup$
2
  • $\begingroup$ Ok, I forgot about CloudEvaluate, thanks! $\endgroup$
    – M.R.
    Nov 26, 2019 at 16:35
  • $\begingroup$ @RolfMertig How does one share a downloadable zip file? $\endgroup$
    – user5601
    Aug 8 at 20:33
1
$\begingroup$

c = CloudPut[a, Permissions -> "Public"] simply puts the file path(an expresstion) of the archived file and not the actual archived contents. So you need to use CopyFile for that. So if your question is about first deploying the content to cloud from desktop Mathametica and archiving it below should work:

In[67]:= a = 
 CreateArchive[FindFile["ExampleData/rose.gif"], 
  OverwriteTarget -> True];

In[68]:=  CopyFile[a, CloudObject["archivedFileOnCloud"]]

Out[68]= CloudObject["https://www.wolframcloud.com/obj/damanjits/\
archivedFileOnCloud"]

(* Also notice that you need to use $HomeDirectory to actually get the path of the
 archived file,  ExtractArchive currently does not work on CloudObject heads
like other file operations like FilePrint, CopyFile etc works *)

In[72]:= CloudEvaluate[
 ExtractArchive[FileNameJoin[{$HomeDirectory, "archivedFileOnCloud"}]]]

Out[72]= {"/wolframcloud/userfiles/050/050bddf0-a081-42a3-88a4-\
576c739a59c2/rose.gif"}

In[78]:= CloudEvaluate[
  Import["/wolframcloud/userfiles/050/050bddf0-a081-42a3-88a4-\
576c739a59c2/rose.gif"]] // Head

Out[78]= Image

If you directly want to do archiving/unarchiving on cloud(I mean on cloud notebook) you can simply use:

In[11]:= file = CreateArchive[FindFile["ExampleData/rose.gif"], "archived.zip"];

In[12]:= Quiet@DeleteFile[FileNameJoin[{$HomeDirectory, "rose.gif"}]]
Import[First@ExtractArchive[file]]//Head

Out[13]= Image



$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.