1

Problem:

I am trying to upload a zip file that contains js files, images, etc. as a Static Resource so that I can reference it in a VF page. I am able to successfully deploy the file using the Ant Migration Tool. However, when I check the resource on force.com, it is empty. This is true regardless of the file type that I have tried (txt, jpg, xml).

Project structure:

I currently have my build and src folders at the same level. Within the build folder I have build.xml and ant-salesforce.jar. Within my src folder I have package.xml and staticresources folder, within which I have the resource (test.resource) and the descriptor file (test.resource-meta.xml).

Any help would be appreciated.

1
  • I have the same problem. Do you have been solved it?
    – One
    Commented May 25, 2022 at 6:54

2 Answers 2

1

The following steps would lead you to success in this question

  • Upload desired static resource to organization by means of Develop -> Static resources -> New with name, for example TestResource
  • Add static resource to package.xml

    <types> <members>TestResource</members> <name>StaticResource</name> </types>

  • Retrieve metadata mentioned in package.xml from organization.

  • Voila! you have valid TestResource.resource and TestResource.resource-meta.xml in staticresources folder.

To read more about static resources and metadata refer to doc

3
  • Thanks for responding! I already have it set up like that And I'm actually trying to deploy rather than retrieve. I have already been able to retrieve data correctly, but I was hoping to be able to deploy a zip via terminal rather than manually creating a new Static Resource on force.com. Do you know if this is possible?
    – bhaff
    Commented Sep 21, 2017 at 17:18
  • I mentioned step, that you need to upload static resource first, because content of static resource is encoded to base64Binary field type. The static resource content. Base 64-encoded binary data. Prior to making an API call, client applications must encode the binary attachment data as base64. Upon receiving a response, client applications must decode the base64 data to binary. This conversion is usually handled for you by a SOAP client. So you have two options: manually convert .zip file to base64Binary type, or let it to do for SF. Commented Sep 22, 2017 at 6:06
  • You fore sure have your own SF org for your own develop/test purposes. Upload desired zip resource to your own org, retrieve resource from there and then deploy it to originally desired SF organization. Commented Sep 22, 2017 at 6:08
0

The test.resource file should be the zip file. Generically speaking, you would do something like this:

$ zip -r src/staticresources/test.resource build/resources/* 

The test.resource file should be the ZIP file in question, and the test.resource-meta.xml should be the metadata for the file.

2
  • Thanks for responding! I already renamed my zip file (previously test.zip) to test.resource. But it still doesn't upload any actual content. It also will occasionally give me "Error: The specified static resource is not a valid zip file", but other times will deploy successfully, just with no content.
    – bhaff
    Commented Sep 21, 2017 at 17:05
  • I too am getting the error message when trying to upload my Ubuntu generated zip File: "Error: The specified Static Resource is not a valid zip file" My Zip command was run from my .../servedcontent/ folder: zip -r bootstrap-4.0.0-dist.zip bootstrap-4.0.0-dist I ran the upload again, it worked just fine. Commented Jul 12, 2019 at 4:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .