Download Assetbundle from the IIS Web site and write to the local disk to specify the path

Source: Internet
Author: User
Tags filezilla

Ah, a deep sigh, a night, and half a day.

Let's talk about the course first, the main step is the pit.

The first thing to pack is needless to say. There are. Asseetbundle, there's u3d, and there's the MD5 list.

Then download and save it is disgusting.

Originally thought is very good, the thought is actually also correct.

Assetbundle generated into the Streamingassets folder
I am on this machine (win10x64), IIS opened a station, opened the FTP, with FileZilla to upload Streamingassets folder on the arrival.
So these assetbundle have the URL: "Http://localhost:9999/StreamingAssets/a.assetbundle"

After uploading, the local streamingassets folder deleted, the program to determine if there is no such folder, then create, download the MD5 list file, according to the list of files listed on the remote server to download all the Assetbundle to local. The code of this process does not say, is not complex, the implementation is also very smooth. The main is from below to start the pit.

Use www, download from the remote URL address, and then write the local path file in binary

string localFilePath = "...";         //要保存到本地的文件全路径string savePath = "...";               //文件存储的文件夹string url = "http://...";                  //要下载的远程文件地址//判断一下文件要存储的文件夹是否存在,不存在则创建if(!Directory.Exists(savePath)){        Directory.CreateDirectory(savePath);}//下载using(WWW www = new WWW(url)){        yield return www;        if(www.error == null && www.isDone)        {                //写入本地文件                File.WriteAllBytes(localFilePath, www.bytes);        }}

OK, so far, there is no error, all the things in the Streamingassets folder are downloaded to the local, look at the file size seems to be no problem.

Since the download, you have to use Ah, or use www bar

string localFilePath="file:///..";             //本地要加载的AssetBundle文件路径using(WWW www = new WWW(localFilePath)){        yield return www;        if(www.error ==null && www.isDone)        {                AssetBundle ab = www.assetBundle;                GameObject go = ab.LoadAsset<GameObject>("go");        }}

Just in this one step

AssetBundle ab = www.assetBundle;

The error:
Failed to decompress data for the Assetbundle ' Memory '

However, please note that there is no problem loading with new WWW (Localfilepath).

Hundred tear not its elder sister, so search engine searches Bai

One way to say it is to set up a binary when uploading to a website FileZilla

OK, set it up, delete the re-upload, or this

So the uploaded files are copied directly, not in the program with the WWW download, you can use, load package no problem

This is not fun, but it is OK to be sure that the problem is to download from remote and save to local this step

Then a different download method

With Unitywebrequest

  using (unitywebrequest req = Unitywebrequest.get (FILEURL)) {                            String FilePath = "...";                            String Savepath = "..."; if (! Directory.Exists (Savepath)) {Directory.CreateDirectory (Savepath                            ); } yield return req.                            Sendwebrequest (); if (Req.isnetworkerror | | req.ishttperror) {debug.logerror (req.                            Downloadhandler.text);  } else {file.writeallbytes (FilePath,                                Req.downloadHandler.data);                            Debug.Log (FILEURL + "downloaded"); }                        }

This time it's more fun, only download the. manifest file, and Assetbundle also. U3d These packages are not downloaded

Look, the error of the report is 404 File not Found

The MIME mappings are also mentioned below.

Degree Niang checked, finally found the real problem.

The program is no problem, the idea is correct, the problem is in the IIS settings

In particular, MIME settings.

That is, in IIS, you need to MIME-map different file types in order to make the files of its type available to be read and downloaded properly on the site side, which is probably the meaning. Let's set it up.

Win+r

Enter Compmgmt.msc carriage return

Click ' Add '

Such as
Extensions fill in the extensions you've packaged, like I'm using Assetbundle and u3d.
MIME type filled in: Application/octet-stream

OK, restart the site, then run, OK, normal download and load, out of a small problem
is the folder named Streamingassets file, which is the same name as the folder, no extension files cannot be downloaded

Check it again.

Or do you want to set mime, no extension?

Or, in the File extension column, fill in a point "."
MIME column or fill in: Application/octet-stream

Okay, OK.

As for the manifest file itself, it is in the default settings of IIS

That is, with IIS, be sure to set your packaged assetbundle file extension type mime, such as the package you hit is Xxx.ab, that AB will set the MIME map like this

Back again, and put unitywebrequest back to the loading mode of WWW, also OK

That is, the problem is in the IIS settings, ideas and procedures are not a problem.

Summarize:

    1. Upload with two-way upload, because it is a binary file
    2. The MIME settings for IIS do well

Problem solving, big satisfaction

Download Assetbundle from the IIS Web site and write to the local disk to specify the path

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.