//========================================================== // Translation //========================================================== // Convert objectId (or source urn) to Base64 encoded urn. // This is an utility. Not using Forge API itself. protected void ButtonToUrn64_Click(object sender, EventArgs e) { // Convert objectId (=source urn) to base64 encoded urn. string objectId = TextBoxObjectId.Text; string urn64 = Forge.ObjectIdToUrn64(objectId); // Show the urn64 in the form. TextBoxUrn64.Text = urn64; // This is not a REST call. We only clear the field with a message. InitRequestResponse("Convert ObjectId to Base64 encoded urn.", ""); }
protected void ButtonTranslate_Click(object sender, EventArgs e) { string accessToken = Session["authToken"] as string; string urn64 = TextBoxUrn64.Text; // Here is the main part that we call Forge API to translate // the file for viewing. bool result = Forge.Translate(accessToken, urn64); // For our learning, // show the request and response in the form. ShowRequestResponse(); }
// Shows a list of objects in the bucket. protected void ButtonObjects_Click(object sender, EventArgs e) { string accessToken = Session["authToken"] as string; string bucketKey = TextBoxBucketKey.Text; // Here is the main part that we call Forge API bucket objects. // Returns a list of bucket objects. string bucketObjects = Forge.GetBucketObjects(accessToken, bucketKey); // For our learning, // show the request and response in the form. ShowRequestResponse(); }
protected void ButtonBucketDetails_Click(object sender, EventArgs e) { string accessToken = HttpContext.Current.Session["authToken"] as string; string bucketKey = TextBoxBucketKey.Text; // Here is the main part that we call Forge API bucket details. // Return value is bucket detail. string details = Forge.GetBucketDetails(accessToken, bucketKey); // For our learning, // show the request and response in the form. ShowRequestResponse(); }
protected void ButtonStatus_Click(object sender, EventArgs e) { string accessToken = Session["authToken"] as string; string urn64 = TextBoxUrn64.Text; // Here is the main part that we call Forge API to check // the status of translation. // Possible value of status: pending/success/inprogress/failed/timeout. string status = Forge.GetManifest(accessToken, urn64); // For our learning, // show the request and response in the form. ShowRequestResponse(); }
//========================================================== // Bucket //========================================================== protected void ButtonBucketCreate_Click(object sender, EventArgs e) { string accessToken = HttpContext.Current.Session["authToken"] as string; string bucketKey = TextBoxBucketKey.Text; string policyKey = "transient"; // transient(24h)/temporary(30days)/persistent // Here is the main part that we call Forge API bucket creation. // Return true if success, false otherwise. bool result = Forge.CreateBucket(accessToken, bucketKey, policyKey); // For our learning, // show the request and response in the form. ShowRequestResponse(); }
//========================================================== // Upload //========================================================== protected void ButtonUpload_Click(object sender, EventArgs e) { string accessToken = Session["authToken"] as string; string bucketKey = TextBoxBucketKey.Text; string objectName = FileUpload1.FileName; byte[] fileData = FileUpload1.FileBytes; // Here is the main part that we call Forge API upload string objectId = Forge.Upload(accessToken, bucketKey, objectName, fileData); // show the objectId = urn:xxx on the page. TextBoxObjectId.Text = objectId; // "urn:xxx" // For our learning, // show the request and response in the form. ShowRequestResponse(); }
//========================================================= // Authentication //========================================================= protected void ButtonToken_Click(object sender, EventArgs e) { string scope = "bucket:create bucket:read data:read data:write"; // Here is the main part that we call Forge authenticate. string authToken = Forge.Authenticate(scope); bool authenticated = !string.IsNullOrEmpty(authToken); if (authenticated) { // Save authToken for this session Session["authToken"] = authToken; // Show the obtained token in the UI. // Note: in real world applications, you don't expose token. // This is for our learning and testing. TextBoxToken.Text = authToken; } // Show the request and response in the form. // This is for learning purpose. ShowRequestResponse(); }