您好,我当前正在尝试保存并上传选定的目标图像并将视频覆盖到 vuforia,但我收到错误,我无法弄清楚这里是我使用的方法以及我在下面遇到的错误。还拿出了访问密钥。
async void OnSaveButtonClicked()
{
string title = titleInputField.text;
if (string.IsNullOrEmpty(title))
{
Debug.LogError("Title cannot be empty.");
return;
}
if (videoRenderTexture == null)
{
Debug.LogError("RenderTexture is null.");
return;
}
Texture2D overlayTexture = GetTextureFromUIImage(overlayImageDisplay);
try
{
await UploadImageToFirebase(overlayTexture);
if (string.IsNullOrEmpty(capturedImageUrl))
{
Debug.LogError("Captured image URL is not set.");
return;
}
await UploadImageToVuforia(overlayTexture);
if (!string.IsNullOrEmpty(selectedVideoPath))
{
await UploadVideoToFirebase(selectedVideoPath);
}
string key = databaseReference.Push().Key;
currentARExperienceData = new Dictionary<string, object>
{
{ "title", title },
{ "capturedImageUrl", capturedImageUrl },
{ "overlayUrl", overlayUrl }
};
Debug.Log("Attempting to save data to Firebase...");
await databaseReference.Child(key).UpdateChildrenAsync(currentARExperienceData);
Debug.Log("Data saved successfully.");
Debug.Log("AR experience saved successfully.");
panelSwitcher.OpenPanel("ProfilePanel");
}
catch (Exception e)
{
Debug.LogError("Failed to save AR experience: " + e.Message);
}
}
私有异步任务UploadImageToVuforia(Texture2D图像) { byte[] imageBytes = EncodeTextureToJPG(image);
string targetName = "MyTarget";
string accessKey = "";
string secretKey = "";
string endpoint = "https://vws.vuforia.com";
var request = new HttpRequestMessage(HttpMethod.Post, $"{endpoint}/targets")
{
Content = new MultipartFormDataContent
{
{ new ByteArrayContent(imageBytes), "file", "image.jpg" },
{ new StringContent(targetName), "name" }
}
};
string date = DateTime.UtcNow.ToString("r");
string stringToSign = $"{request.Method}\n\n\n{imageBytes.Length}\n{date}\n/targets";
string signature = GenerateSignature(stringToSign, secretKey);
request.Headers.Add("Authorization", $"VWS {accessKey}:{signature}");
request.Headers.Add("Date", date);
HttpClient client = new HttpClient();
try
{
HttpResponseMessage response = await client.SendAsync(request);
string responseBody = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
Debug.Log("Image successfully uploaded to Vuforia!");
}
else
{
Debug.LogError($"Vuforia upload failed: {response.ReasonPhrase}");
Debug.LogError("Response body: " + responseBody);
}
}
catch (Exception e)
{
Debug.LogError("Vuforia upload failed: " + e.Message);
}
}
private string GenerateSignature(string stringToSign, string secretKey)
{
var encoding = new System.Text.ASCIIEncoding();
byte[] keyBytes = encoding.GetBytes(secretKey);
byte[] messageBytes = encoding.GetBytes(stringToSign);
using (var hmacsha1 = new System.Security.Cryptography.HMACSHA1(keyBytes))
{
byte[] hashmessage = hmacsha1.ComputeHash(messageBytes);
return Convert.ToBase64String(hashmessage);
}
}
}上传失败:未经授权 UnityEngine.Debug:LogError(对象) CreateARManager/d__37:MoveNext ()(位于 Assets/Scripts/CreateARManager.cs:366) UnityEngine.UnitySynchronizationContext:执行任务()
响应正文:{"result_code":"AuthenticationFailure","transaction_id":"e58338366f80453fa91d67fbc0f6baf8"} UnityEngine.Debug:LogError(对象) CreateARManager/d__37:MoveNext ()(位于 Assets/Scripts/CreateARManager.cs:367) UnityEngine.UnitySynchronizationContext:执行任务()
AR体验保存失败:该方法或操作未实现。 UnityEngine.Debug:LogError(对象) CreateARManager/d__33:MoveNext ()(位于 Assets/Scripts/CreateARManager.cs:257) System.Threading.Tasks.TaskCompletionSource`1:SetResult (int) Firebase.FutureVoid/<>c__DisplayClass4_0:b__0 () (位于 /home/runner/work/firebase-unity-sdk/firebase-unity-sdk/linux_unity/app/swig/Firebase.App_fixed.cs:1368) Firebase.FutureVoid:SWIG_CompletionDispatcher(int)(位于/home/runner/work/firebase-unity-sdk/firebase-unity-sdk/linux_unity/app/swig/Firebase.App_fixed.cs:1456) Firebase.AppUtil:PollCallbacks () (位于 /home/runner/work/firebase-unity-sdk/firebase-unity-sdk/linux_unity/app/swig/Firebase.App_fixed.cs:4656) Firebase.Platform.FirebaseAppUtils:PollCallbacks () (位于 /home/runner/work/firebase-unity-sdk/firebase-unity-sdk/app/platform/FirebaseAppUtils.cs:33) Firebase.Platform.FirebaseHandler:Update () (位于 /home/runner/work/firebase-unity-sdk/firebase-unity-sdk/app/platform/Unity/FirebaseHandler.cs:208) Firebase.Platform.FirebaseMonoBehaviour:更新()(位于/home/runner/work/firebase-unity-sdk/firebase-unity-sdk/app/platform/Unity/FirebaseMonoBehaviour.cs:45)
我尝试使用不同的方法,检查访问密钥是否正确,并确保我使用的是服务器密钥。检查终点是否正确。
检查您的StringToSign的格式,使其符合规范:
对请求的共享密钥签名字符串进行编码 Blob 或队列服务的 2009-09-19 版本及更高版本以及版本 2014-02-14 及更高版本的文件服务,使用以下格式:
StringToSign = VERB + "\n" +
Content-Encoding + "\n" +
Content-Language + "\n" +
Content-Length + "\n" +
Content-MD5 + "\n" +
Content-Type + "\n" +
Date + "\n" +
If-Modified-Since + "\n" +
If-Match + "\n" +
If-None-Match + "\n" +
If-Unmodified-Since + "\n" +
Range + "\n" +
CanonicalizedHeaders +
CanonicalizedResource;