python |
Pythonタグが付けられた新着投稿 - Qiita |
Azure MLのジョブのStatusを確認する方法 |
https://qiita.com/kkawano_neko/items/f7cb174d50dfb59706a4
|
oswindowsnvidiagtxti |
2022-11-29 20:41:40 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
Flaskでデータベースが作成されない時〜RuntimeErrorを読み解く〜 |
https://qiita.com/sasao-genmaicha/items/57e2c6758e1aa8df7ae0
|
flask |
2022-11-29 20:15:43 |
Linux |
Ubuntuタグが付けられた新着投稿 - Qiita |
GitHub Actions Workflow ubuntu-latest が 22.04 に |
https://qiita.com/Satachito/items/ce3c22081fb0b4aded03
|
ubuntu |
2022-11-29 20:23:46 |
Azure |
Azureタグが付けられた新着投稿 - Qiita |
Azure MLのジョブのStatusを確認する方法 |
https://qiita.com/kkawano_neko/items/f7cb174d50dfb59706a4
|
oswindowsnvidiagtxti |
2022-11-29 20:41:40 |
技術ブログ |
Developers.IO |
【レポート】Leading beyond line of sight: Amazon’s two-pizza teams #INO204 #reinvent |
https://dev.classmethod.jp/articles/reinvent-ino204-two-pizza-teams/
|
amazon |
2022-11-29 11:19:33 |
技術ブログ |
Developers.IO |
【Amazon S3 Glacier】 復元のスループットが最大 10 倍に向上してました! |
https://dev.classmethod.jp/articles/10x-restore-throughput-increase/
|
amazons |
2022-11-29 11:08:28 |
技術ブログ |
Developers.IO |
[レポート][CON406] AWS Fargate と AWS App Runner の詳細を見てみよう #reinvent |
https://dev.classmethod.jp/articles/report-con406-reinvent2022/
|
awsfargateandawsapprunner |
2022-11-29 11:04:32 |
海外TECH |
MakeUseOf |
How to Downgrade to an Older Version of iOS |
https://www.makeuseof.com/how-to-downgrade-ios/
|
learn |
2022-11-29 11:30:16 |
海外TECH |
DEV Community |
Rest api to upload images in Go |
https://dev.to/mavensingh/rest-api-to-upload-images-in-go-1g21
|
Rest api to upload images in GoIn this article we are going to learn about how we can create a rest api to upload image we ll also going to make sure that our api will handle multiple image upload as well and we are also going to set the file upload limit so it won t make our system unstable because long file upload can cause the system failure issue so it s better to add a limit for the file and we are going to make sure that we only accept image so we also need to add file type checking as well for our api if you want images and docs from the same api you can remove the type checking filter and api is ready to handle multiple type files Steps we need to follow to make our rest api to upload images Create Repostory Setup go mod Create main go fileSetup http server using gorilla mux package Create the api Connect the rest api with http handler Test the api Let s follow the steps one by one to create the successfull rest api to upload images Create RepositoryFirst we need to create the folder where we can setup our codebase Create a folder called upload images rest api below is the command to create directory folder mkdir upload images rest api Setup go modWe also need to setup go mod file in upload images rest api folder so we can use our code as package module below is the command to generate the go mod file go mod init upload images rest apiIf you are new to Go then you might need to understand the go packaging first to understand what this command do Create main go fileInside your upload images rest api folder create another file called main go touch main goas now we have also created our main go file now we can start development of our http server Setup http server using gorilla mux packageFor creating server we are going to use gorilla mux package so first we need to download the package first then we can start the development Below is the command to download the gorilla mux package go get u github com gorilla mux After the installation of gorilla mux we can start the development of our code Create main function First we need to write the boiler plate code of Go below is the codepackage mainfunc main As of now it s a boiler plate code that s why we don t have any package loaded yet Create HTTP Server Below is the code of the http server package mainimport log net http github com gorilla mux const PORT func main r mux NewRouter r HandleFunc ping nil Methods GET r HandleFunc upload nil Methods POST log Printf Server is running on http localhost s PORT log Println http ListenAndServe PORT r First we added the PORT variable in which we want our server to run which is Inside the main function we have called the mux NewRouter function of our gorilla mux package and then we have created our routes as mentioned in the code and also attached their methods as well as you can see we have two API first pingis to check if our server is alive or not and second upload is for our main work to upload images then we re passing our mux router to http ListenAndServe function and also passing the port on we want our server to run If you try to run the server and go to test any of the api you ll get the error like this because we just passed the path but for the provided path their is no handler which can read that handle that request http panic serving runtime error invalid memory address or nil pointer dereferencegoroutine running net http conn serve func C Program Files Go src net http server go xbfpanic xe xde C Program Files Go src runtime panic go xnet http HandlerFunc ServeHTTP xc xebd xce x C Program Files Go src net http server go xegithub com gorilla mux Router ServeHTTP xc xebd xce xc C Users KDSINGH go pkg mod github com gorilla mux v mux go xcfnet http serverHandler ServeHTTP xc xebd xce xc C Program Files Go src net http server go xcnet http conn serve xce xebd xc C Program Files Go src net http server go xcreated by net http Server Serve C Program Files Go src net http server go xdbTo solve this issue let s create our a http handler for our ping api which will be used as a api heartbeat to check if server is running or not Let s add the handler for the ping route func Ping w http ResponseWriter r http Request answer map string interface messageType S message data PONG w Header Set Content Type application json w WriteHeader json NewEncoder w Encode answer We have added the Ping function to handle the ping route and inside the Ping function we have added our response structure as map string interface so we can add dynamic response as we want we re not dependent on struct We have added messageType message and data as our response we going to use the same response json for our upload api expect that data will be going to a struct with multiple fields In next we re write our header content type and http code and then encoding and directly returning back our response as json Add Ping function into handlerNow we have our Pingfunction let s add this in our ping handler r HandleFunc ping Ping Methods GET Now we have added our Ping handler as well Let s test the API You can test the api using postman or your browser as ping doesn t accepts any parameter so it can be test on browser as well PostmanBrowser ping is working as expected now it s time to implement our main handler as well Create the api to upload imagesBelow is the full code of upload image rest api handler to handle the image uploadfunc UploadImages w http ResponseWriter r http Request MB is the default used by FormFile function if err r ParseMultipartForm BULK FILE SIZE err nil http Error w err Error http StatusInternalServerError return Get a reference to the fileHeaders They are accessible only after ParseMultipartForm is called files r MultipartForm File file var errNew string var http status int for fileHeader range files Open the file file err fileHeader Open if err nil errNew err Error http status http StatusInternalServerError break defer file Close buff make byte err file Read buff if err nil errNew err Error http status http StatusInternalServerError break checking the content type so we don t allow files other than images filetype http DetectContentType buff if filetype image jpeg amp amp filetype image png amp amp filetype image jpg errNew The provided file format is not allowed Please upload a JPEG JPG or PNG image http status http StatusBadRequest break err file Seek io SeekStart if err nil errNew err Error http status http StatusInternalServerError break err os MkdirAll uploads os ModePerm if err nil errNew err Error http status http StatusInternalServerError break f err os Create fmt Sprintf uploads d s time Now UnixNano filepath Ext fileHeader Filename if err nil errNew err Error http status http StatusBadRequest break defer f Close err io Copy f file if err nil errNew err Error http status http StatusBadRequest break message file uploaded successfully messageType S if errNew message errNew messageType E if http status http status http StatusOK resp map string interface messageType messageType message message w Header Set Content Type application json w WriteHeader http status json NewEncoder w Encode resp We have added our new handler UploadImages and added the check for limited size data upload for our upload endpoint we re passing the BULK FILE SIZE into r ParseMultipartForm function In next step we re getting the all uploaded file using r MultipartForm File file and it s giving us the map string multipart FileHeader on which we re iterating our loop sequentially Inside the loop first we re opening the file using fileHeader Open and processing the returned information file next we re reading the opened file information in chunks buff make byte using file Read buff function we re passing our opened file to Read method and also passing the bytes we need to read from the opened file After reading small chunk from file we re passing that chunks http DetectContentType function and it s returning back the file type and in next step we re checking file type we re only accepting JPEG JPG and PNG images In next step we re calling file Seek io SeekStart for seeking image data fron given offset to whence then we re creating the uploads folder in the root level of the project after creating folder we re creating the file where we can save the image data we have opened and in next we re calling io Copy f file and passing the data file into our newly created file f In the end of the function we re just processing the request and we need if the function got any error processing the image then it ll return the error otherwise it ll return back the successfull message as type json response Connect the rest api with http handlerNow we have our handler for upload api but it s not connected yet so let s connect it and then we ll test our code We just need to add the UploadImages function as second argument into our upload handlefunc r HandleFunc upload UploadImages Methods POST Test the API We have connected our handlers with our routers It s time to test the upload route This article is originally posted on programmingeeksclub comMy Personal Blogging Website Programming Geeks ClubMy Facebook Page Programming Geeks ClubMy Telegram Channel Programming Geeks ClubMy Twitter Account Kuldeep SinghMy Youtube Channel Programming Geeks Club |
2022-11-29 11:38:53 |
Apple |
AppleInsider - Frontpage News |
How to get older apps for iPhone that can't run iOS 16 |
https://appleinsider.com/inside/iphone/tips/how-to-get-older-apps-for-iphone-that-cant-run-ios-16?utm_medium=rss
|
How to get older apps for iPhone that can x t run iOS If you have an older iPhone that still runs like a champ but can t run iOS all is not lost Here s how to get an older version of the app you want that will still work on your iPhone If your iPhone can t run iOS you can still download older versions of the app These instructions work with some variance depending on operating system on devices older than the iPhone and the original iPhone SE Here s an easy step by step guide on how to do it Read more |
2022-11-29 11:40:17 |
Apple |
AppleInsider - Frontpage News |
Whill Model F Travel Chair review: What Apple would make, if it wanted to |
https://appleinsider.com/articles/22/11/28/whill-model-f-travel-chair-review-what-apple-would-make-if-it-wanted-to?utm_medium=rss
|
Whill Model F Travel Chair review What Apple would make if it wanted toWe ve driven the Whill s Model F power wheelchair nearly daily over six months We can say without a single doubt that it is the wheelchair that Apple would make if it was in the market to do so Whill Model F wheelchair in the fieldI am not the one who needs this chair so a little bit of a preamble is in order Our test driver had a stroke in resulting in a left side vision cut general left side weakness and lack of control plus hampered mobility She isn t profoundly cognitively impaired and can still walk short distances without more assistance than use of a cane or hemi walker Read more |
2022-11-29 11:27:13 |
ニュース |
BBC News - Home |
Less than half of England and Wales population Christian, Census 2021 shows |
https://www.bbc.co.uk/news/uk-63792408?at_medium=RSS&at_campaign=KARANGA
|
wales |
2022-11-29 11:50:32 |
ニュース |
BBC News - Home |
Quarter of 17-19-year-olds have probable mental disorder - study |
https://www.bbc.co.uk/news/health-63784751?at_medium=RSS&at_campaign=KARANGA
|
health |
2022-11-29 11:42:21 |
ニュース |
BBC News - Home |
China Covid: Chinese protesters say police seeking them out |
https://www.bbc.co.uk/news/world-asia-china-63785351?at_medium=RSS&at_campaign=KARANGA
|
covid |
2022-11-29 11:31:35 |
ニュース |
BBC News - Home |
World Cup: Warning over football lottery scams |
https://www.bbc.co.uk/news/business-63793641?at_medium=RSS&at_campaign=KARANGA
|
letters |
2022-11-29 11:22:53 |
ニュース |
BBC News - Home |
Tilda Swinton: Cinema was a haven and a sanctuary |
https://www.bbc.co.uk/news/uk-scotland-63793876?at_medium=RSS&at_campaign=KARANGA
|
archive |
2022-11-29 11:47:06 |
ニュース |
BBC News - Home |
Pakistan v England: James Anderson says tourists may have to be 'creative' |
https://www.bbc.co.uk/sport/cricket/63674347?at_medium=RSS&at_campaign=KARANGA
|
Pakistan v England James Anderson says tourists may have to be x creative x Pace bowler James Anderson says England may have to be creative in order to win the first Test against Pakistan in Rawalpindi on Thursday |
2022-11-29 11:20:12 |
海外TECH |
reddit |
大数据和大监控是把双刃剑,上海公安系统被黑,黑客要求放人 |
https://www.reddit.com/r/real_China_irl/comments/z7r8v3/大数据和大监控是把双刃剑上海公安系统被黑黑客要求放人/
|
rrealchinairllinkcomments |
2022-11-29 11:18:47 |
コメント
コメントを投稿