How can can i insert a user with profile picture using Blazor-server - asp.net-core

I want the user to upload his picture when he registers his information.
The thing is when the user uploads his image.. should automatically create a folder with his ID to be like this wwwroot/images/UserID/fadi.jpg

Basically: you really shouldn't. The wwwroot is for static assets used by the application. You're using server-side, so in theory it might be possible but that's not what the folder is meant for. An alternative method like AWS would be preferred, but if you can't do that (either because of payment requirements or other complications) I would suggest saving the image to your database. One way to do this would be to base64 encode the image and save it that way. I'm not going to give an example of that here, there are plenty available elsewhere. One such example is this.

Related

In ASP.NET Core MVC, how do you make uploaded images accessible to logged users in app but not to general public?

I have image upload in my system. I am struggling to understand what is the logic of serving images.
If I upload directly to wwwroot, the files will be accessible to everyone, which is not what I want.
I understand I could save the file contents in the database as base64 but those can be big files, and I would like them on the server in files.
I could convert them on the fly when requested. Most probably getting the path to file, then loading it in a memory stream and spitting out the base64. But seems overkill, and not an elegant solution. I use Automapper for most data and I have to write some crazy custom mappers, which I will If there is no other way.
I could create virtual path, which from what I understand maps physical path on server to a url which doesn't seem any different than option 1
I fancy there is a way to spit out a link/url that this user has access to (or at least logged users) that can be passed to the app so it can load it. Is this impossible or unreasonable? Or am I missing something?
What is the correct way of doing in general?
Also, what is a quick way to do it without spending days for setup?
To protect the specific static files, you can try the solutions explained in this official doc.
Solution A: Store static files you want to authorize outside of wwwroot, and call UseStaticFiles to specify a path and other StaticFileOptions after calling UseAuthorization, then set the fallback authorization policy.
Solution B: Store static files you want to authorize outside of wwwroot, and serve it via a controller action method to which authorization is applied and return a FileResult object.

PHAsset - Property way to save captured PHAssets locally? (in app)

trying to understand the concept for Photos/Photos.h framework.
my goal is:
write captured video url (or asset) to app's "userDefaults".
read from "userDefaults", & fetch each saved asset data (thumbnail & url)
Since you're not providing any code (nor asking for any), I can help sort some of this out for you -- but you need to study a bit more before you can put it all together. Especially if you think you've asked a question which has one simple correct answer.
UserDefaults is not a good place to store an image. Images are big. (You should look at Apple's documentation of what UserDefaults is for/how it's intended use).
UserDefaults
There's more than one place to store images. Do you want the system to delete them if you start running out of memory? Then it belongs in cache:
let cachesPath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).last!
Do you want to depend on it being around the next time the app is run? There is a standard place for that as well:
let userDocumentsFolder = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
Do you want iTunes to back up the images for you automatically? It expects files to be in a certain place for automatic backup. Do you have a way to keep track of where it is (the path to the file can change if the app is re-run). For that you might require persistent storage, so CoreData or Realm might be an option for you. Or you could scan your directory and create a list of files you've already saved. Then you'll need a way to select the correct one. (What did you call it? Should the user select it?)
Apple has very clearly written and useful documentation on access to the Photos library and using PHAssets. Here's just one example:
PHAsset - Photos
There are a lot of talented people on this site, and they are willing to help you, but you need to do your homework before coming here.
I recommend you read these linked documents, start writing some code, and if you run into problems please come back and ask any specific question you have about any specific problem you've encountered. Include the code which causes the problem, as well as the exact error message you are getting. We will be glad to help.

Joomla: Allowing a user to upload an image

Alright so I learned that to have an upload button on a page, what you do is basically call a php file (call is upload.php) that would upload a file to the server. I have no idea where I am supposed to put the php file inside the server so I can call it.
I feel stupid because I can't find any answers online. I am getting very frustrated and confused because I am told I need to create a database but I have no idea how to edit a database in Joomla. I took a class in SQL so I don't have to learn about that. I just don't know where it is. I was also told I need to make a component. But this is confusing because all I want to do is have an upload button that will upload an image to the server.
I understand your frustration. I've got the basic idea on what you are trying to do. Here are a couple of options:
You might wanna take a look at Joomla! Extensions Directory ™. You might just find there a component or a module that already does this for you.
If you want to do it on your own, than you need to create a small module or a component inside Joomla! Please refer to the Joomla! Documentation or tutorials on this topic. Please note that you won't get this working instantly, because you first need to understand how Joomla! works. So your upload.php file will go in your module / component files. I don't think you need to do any SQL.
Now the part with "allowing a user" is a bit confusing... you want to "allow" any user to upload things to your server or just let's say, registered users? Generally uploading scripts need to be very strong from the security point of view. If this is the case, that you need to do a search for Joomla! ACL
You can simply create a form and add the "media" field type.
http://docs.joomla.org/Standard_form_field_types
You can also opt for the "file" field types to allow different types of fields.
Both fields can be added using the Joomla Component Creator: http://www.notwebdesign.com/joomla-component-creator/
And you might also want to take a look at K2 which has an excellent image upload functionality that allows scaling of images into three different sizes.

Using JSON to update app's content in iOS

I'm about to create an application that uses JSON to update its content.
This is how I planned it to work:
When application starts, it checks (with internet connection is available) if the JSON file set on remote server is newer than the one stored localy - if it is then it's downloaded.
Then, the application applies data from that JSON to the content. For example, to the "Contact" information - it applies data like phone numbers etc.
My question is, is it in your opinion, a good technique to update appliactions content?
Does anynone had an experience with building app with this kind of idea?
Best regards,
Zin
Of course you can do this. One thing that may lead to a better user experience would be to ask the user for his permission to download new content (if there is something new).
This is a normal thing to do. I have a phonebook app that does exactly this. On a side note, if you need a network class to handle the web-service interaction, see this SO post. I wrote a custom network class that works with AFNetworking.

How do I implement a secure upload/download area?

I've been asked to create a solution where people log in and are able to upload and download off of our work server. So John uploads a photo, and Jen can download it, for example. They also have to authenticate themselves.
Can someone give me a rough overview of how to implement this? I'm familiar enough with MySQL, C#, and JavaScript.
The rough overview
This should just be a matter of planning out the pieces.
at the very top of the page, put some code that checks if a user is logged in. If not, show a login form (or redirect to...). If they are logged in, show the rest of the page. If not, you'll need some logic to show a form, and then check it once it's submitted for authentication, and set a SESSION cookie or something similar.
Once the user is logged in, on the homepage, you might have an file-upload form and a listing of existing files. How you would style would depend on how many files you might expect to have. To keep things extremely simple, you could simple iterate through whatever files are in the upload directory. If you expect many more files than that, you may consider using a db.
Handle a file upload by sanitizing filenames (checking for filetype/filesize if you want to limit those) and putting the file into the directory.
Force the users to download the files (instead of having the browser decide what to do with them) for security purposes. Implementing this on certain filetypes may also be acceptable.
Other thoughts
You probably would not want the users to be able to excecute any files, so keeping the file directory hidden would be a good idea.
Keeping track of who uploaded and downloaded what is also doable, but would add another layer of complication to the script.