Website File Hosting
If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference
You can perform the following to implement website file hosting:
- Upload the website files to your bucket in OBS as objects and set the MIME type for the objects.
- Set the object ACL to public-read.
- Access the objects using a browser.
Sample code:
// Create an instance of ObsClient.
ObsClient client = new ObsClient("*** Provide your Access Key ***", "*** Provide your Secret Key ***", "https://your-endpoint");
try
{
//Set the MIME type for an object.
PutObjectRequest request = new PutObjectRequest
{
BucketName = "bucketname",
ObjectKey = "test.html",
FilePath = "localfile.html",// Path of the local file uploaded. The file name must be specified.
CannedAcl = CannedAclEnum.PublicRead,//Set the object ACL to public-read.
ContentType = "text/html",
};
// Upload an object.
PutObjectResponse response = client.PutObject(request);
Console.WriteLine("put object response: {0}", response.StatusCode);
}
catch (ObsException ex)
{
Console.WriteLine("ErrorCode: {0}", ex.ErrorCode);
Console.WriteLine("ErrorMessage: {0}", ex.ErrorMessage);
}
You can use https://bucketname.your-endpoint/test.html in a browser to access files hosted using the sample code.
Last Article: Static Website Hosting Overview
Next Article: Setting Website Hosting
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.