Hass
Hass
Explore posts from servers
CC#
Created by Hass on 3/7/2025 in #help
Converting json to MemoryStream and back breaks the json
For context, I have the following JSON (most of the stuff omitted for brevity):
{"schemaId":"azureMonitorCommonAlertSchema","data":{...}}
{"schemaId":"azureMonitorCommonAlertSchema","data":{...}}
After I convert it to a MemoryStream and back to string, it surrounds the string with quotation marks and re-escapes the already-escaped characters. Method used to convert to MemoryStream:
internal static MemoryStream CreateMemoryStream(this string data)
{
byte[] byteArray = Encoding.UTF8.GetBytes(data);
MemoryStream stream = new(byteArray) { Position = 0 };
return stream;
}
internal static MemoryStream CreateMemoryStream(this string data)
{
byte[] byteArray = Encoding.UTF8.GetBytes(data);
MemoryStream stream = new(byteArray) { Position = 0 };
return stream;
}
I also tried using a StreamWriter approach, but to no avail. The snippet of code that converts the MemoryStream back to string:
using StreamReader reader = new(ms, encoding: System.Text.Encoding.UTF8, leaveOpen: true);
string result = await reader.ReadToEndAsync();
using StreamReader reader = new(ms, encoding: System.Text.Encoding.UTF8, leaveOpen: true);
string result = await reader.ReadToEndAsync();
It results in the following broken JSON:
"{\"schemaId\":\"azureMonitorCommonAlertSchema\",\"data\":{...}}"
"{\"schemaId\":\"azureMonitorCommonAlertSchema\",\"data\":{...}}"
I can't pinpoint exactly why this is happening, I guess it has to do with the fact that when it reads it back to a string, because the content is already a "string", it escapes the already-escaped quotes and surrounds it with the quotemarks. I don't know how to avoid this behaviour tho. Edit: change wording
54 replies
FFilament
Created by Hass on 2/11/2024 in #❓┊help
HasMany relationship by only using where clause (for RelationManager)
No description
2 replies
FFilament
Created by Hass on 1/13/2024 in #❓┊help
User being able to see resource in the navigation even without permission
(I'm using bezhansalleh's shield plugin) I'm testing with two users: one (the super_admin one) has every permission, the other just a few of them. The second user does not have the viewAny permission neither the specific permission to see the resource. (If I run Policy->viewAny($second_user) it returns false) Even though the user does not have the permission to see the resource, it shows on the menu. One thing that I noted is that this behavior only happens with resources, individual pages are properly hidden from the user. I tested with two different resources and it happens to both of them. I'm kinda new to filament and laravel in general, so I may be missing something, but I followed the plugin's (shield) instructions and everything else is working fine (afaik) besides this. I'm not sure on what to share to help, but just ask me anything and I'll send asap edit: formating; typo
17 replies
CC#
Created by Hass on 12/25/2022 in #help
❔ Getting error 500 on form post (using fetch)
I'm trying to do a form post (posting a model), but my controller is not being called. When I check the fetch result on the console, I get a 500 error, but I haven't been able to pinpoint where the problem lies. The model:
public class PostModel
{
public List<string> ImagesPath { get; set; }
public string Description { get; set; }
}
}
public class PostModel
{
public List<string> ImagesPath { get; set; }
public string Description { get; set; }
}
}
The js object I'm posting/ the fetch post:
document.querySelector("#enviaForm").addEventListener("click", function(e) {
const postsToSend = createPostObjectToSend()
// postsToSend is an array composed of objects that looks like this:
// {
// Description: post.querySelector("input[type=text]").value.trim(),
// ImagesPath: []
// }

fetch('/Home/ProcessPosts', {
method: 'POST',
body: postsToSend
})
.then(response => response)
.then(data => {console.log(data)})
})
document.querySelector("#enviaForm").addEventListener("click", function(e) {
const postsToSend = createPostObjectToSend()
// postsToSend is an array composed of objects that looks like this:
// {
// Description: post.querySelector("input[type=text]").value.trim(),
// ImagesPath: []
// }

fetch('/Home/ProcessPosts', {
method: 'POST',
body: postsToSend
})
.then(response => response)
.then(data => {console.log(data)})
})
The ImagesPath is an array of strings, where I get the values from inputs of the type 'file'. The controller
[HttpPost]
public void ProcessPosts(List<PostModel> post)
{

}
[HttpPost]
public void ProcessPosts(List<PostModel> post)
{

}
Maybe I'm missing some basic concept or basic knowledge? I've been trying to fix this for hours but I haven't been able to
38 replies
CC#
Created by Hass on 11/7/2022 in #help
FormCollection converting value from input='text'
1 replies