Невозможно загрузить пользователя в библиотеку изображений лиц в камере Hikvision.C#

Место общения программистов C#
Ответить
Anonymous
 Невозможно загрузить пользователя в библиотеку изображений лиц в камере Hikvision.

Сообщение Anonymous »

Я пытаюсь использовать ISAPI для загрузки пользователя в библиотеку изображений лиц, но не знаю, в чем ошибка. Он всегда отвечает внутренней ошибкой сервера. Можете ли вы помочь мне определить проблему?
ниже приведен мой код
это моя страница бритвы:

Код: Выделить всё

@page "/libraryUser"
@inject FaceLibraryUser FaceLibraryUser
@inject HttpClient Http

Send Face Data

Submit

@statusMessage

@code {
private string statusMessage = "Please select an image.";
private IBrowserFile selectedFile;
private string selectedFileName;
private InputFile fileInput;

private void OnFileSelected(InputFileChangeEventArgs e)
{
selectedFile = e.File;
if (selectedFile != null)
{
selectedFileName = selectedFile.Name;
statusMessage = $"File selected: {selectedFile.Name}";
}
else
{
statusMessage = "No file selected.";
}
}

private async Task SubmitData()
{
if (selectedFile == null)
{
statusMessage = "Please select an image before submitting.";
return;
}

try
{
using var stream = selectedFile.OpenReadStream();
using var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream);
var imageBytes = memoryStream.ToArray();

// Call the function from the FaceLibraryUser service
var result = await FaceLibraryUser.UploadFaceToLibrary(2, "test", imageBytes, selectedFileName);

statusMessage = result;
}
catch (Exception ex)
{
statusMessage = $"Error: {ex.Message}";
}
}
}
это моя страница CS:

Код: Выделить всё

using System.Net;
using System.Net.Http.Headers;
using System.Text;
using System.Xml.Linq;

public class FaceLibraryUser
{
public static async Task UploadFaceToLibrary(int fdid, string name, byte[] selectedImage, string fileName)
{
if (selectedImage == null || selectedImage.Length == 0)
{
return "Please select an image file first.";
}

var url = "http://192.168.2.64/ISAPI/Intelligent/FDLib/pictureUpload";

// Prepare the XML data
var xmlContent = new XElement("PictureUploadData",
new XElement("FDID", fdid),
new XElement("FaceAppendData",
new XElement("name", 1234))
).ToString();

// Convert the XML content to binary format
var xmlBytes = Encoding.UTF8.GetBytes(xmlContent);
var xmlBinaryContent = new ByteArrayContent(xmlBytes);
xmlBinaryContent.Headers.Add("Content-Disposition", "form-data; name=\"PictureUploadData\"");

// Create content for the image part
var imageContent = new ByteArrayContent(selectedImage);
imageContent.Headers.Add("Content-Disposition", $"form-data; name=\"importImage\"; filename=\"{fileName}\"");
imageContent.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");

var boundary = GenerateCustomBoundary();

// Manually construct the multipart form data
using var content = new MultipartFormDataContent(boundary);
content.Add(xmlBinaryContent);
content.Add(imageContent);

// Set up HttpClient with HttpClientHandler for Basic Authentication
var handler = new HttpClientHandler
{
Credentials = new NetworkCredential("admin", "iDS-2CD7146G0-IZ") // Replace with your credentials
};

using var client = new HttpClient(handler);
client.DefaultRequestHeaders.Add("Cache-Control", "no-control");
client.DefaultRequestHeaders.Add("Connection", "keep-alive");
client.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest");   // Add X-Requested-With header

try
{
// Send the POST request
var response = await client.PostAsync(url, content);
if (response.IsSuccessStatusCode)
{
return "User added successfully.";
}
else
{
var errorResponse = await response.Content.ReadAsStringAsync();
return $"Failed to add user. Status Code: {response.StatusCode}, Reason: {errorResponse}";
}
}
catch (Exception ex)
{
return $"Error: {ex.Message}";
}
}

// Generate custom boundary: 26 dashes followed by 24 digits
private static string GenerateCustomBoundary()
{
var random = new Random();
var digits = new StringBuilder();

// Generate 24 random digits
for (int i = 0; i < 24; i++)
{
digits.Append(random.Next(0, 10)); // Random digit between 0 and 9
}

return new string('-', 26) + digits.ToString();
}
}

Код: Выделить всё

below is my error message:
Failed to add user. Status Code: InternalServerError, Reason:    3 Device Error deviceError deviceError. The HTTP request is abnormal. Please first confirm whether the device version is supported and whether the request content conforms to the protocol standard, or contact technical support to provide help. Thank you; 
изображение ошибки: errorMessage
Я надеюсь, что смогу найти ошибку и решение и успешно загрузить пользователя в библиотеку изображений лиц

Подробнее здесь: https://stackoverflow.com/questions/792 ... ion-camera
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»