winjs

Uploading a photo using XMLHtttpRequest to a Flask webserver

梦想的初衷 提交于 2021-02-08 04:40:50
问题 I'm creating a WinJS app and using XMLHttpRequest to send a photo as a blob to a Flask webserver. openPicker.pickSingleFileAsync().then(function (file) { file.openAsync(Windows.Storage.FileAccessMode.read).done(function (stream) { var blob = MSApp.createBlobFromRandomAccessStream("application/octet-stream", stream); var fdata = new FormData(); fdata.append("file", blob, "photo.jpg"); var xmlhttp = new XMLHttpRequest(); xmlhttp.open("POST", "http://127.0.0.1:5000/api/addPhoto", true); xmlhttp

Uploading a photo using XMLHtttpRequest to a Flask webserver

☆樱花仙子☆ 提交于 2021-02-08 04:40:28
问题 I'm creating a WinJS app and using XMLHttpRequest to send a photo as a blob to a Flask webserver. openPicker.pickSingleFileAsync().then(function (file) { file.openAsync(Windows.Storage.FileAccessMode.read).done(function (stream) { var blob = MSApp.createBlobFromRandomAccessStream("application/octet-stream", stream); var fdata = new FormData(); fdata.append("file", blob, "photo.jpg"); var xmlhttp = new XMLHttpRequest(); xmlhttp.open("POST", "http://127.0.0.1:5000/api/addPhoto", true); xmlhttp

「走过」微软、优步,老工程师告诉你哪些数据结构和算法最重要

风格不统一 提交于 2020-08-13 03:24:08
数据结构和基础算法作为计算机科学的必学课程,近几年却关注度越来越少。但 程序员真的不再需要这两门基础知识了吗 ?一位在 Uber 等科技公司工作过的开发者分享了他的一手经验,告诉你实际工作中会用到哪些数据结构和算法。 作者:Gergely Orosz,机器之心编译,参与:小舟、杜伟。 日常工作中,你经常使用算法和数据结构吗?曾就职于 Uber 等科技公司的工程师 Gergely Orosz 提出了这样一个问题。此外,他也注意到,越来越多的人觉得算法是无用的,并认为它们只是科技公司提出的一种强制性措施罢了。 本文作者 Gergely Orosz。 不仅如此,也有更多的人抱怨称算法只是纯粹的学术练习。在 Homebrew 作者 Max Howell 发表他的谷歌面试经历之后,这样的想法被进一步普及。 虽然 Gergely Orosz 自己也从来不需要使用二叉树翻转(binary tree inversion),但是他在 Skype、Microsoft、Skyscanner 以及 Uber 工作时,每天都会遇到使用数据结构和算法的情况。 此外,他有时也需要基于这些概念编写代码和做出决策。最后,Gergely Orosz 借助这些知识来理解有些事物如何和为何构建,以及如何使用或修改它们。 由此可见,数据结构和算法并不是如人们所言用处不大。在本文中,Gergely Orosz

WinJS are there #DEBUG or #RELEASE directives?

╄→尐↘猪︶ㄣ 提交于 2020-02-06 06:48:26
问题 I would like to exclude some code when using release vs debug. Basically I have an internal admin section for testing that I don't to ever make it into the app store by accident :) Ideally, I would just be able to do something like this: #IF DEBUG <div id="appBar" data-win-control="WinJS.UI.AppBar"> <button data-win-control="WinJS.UI.AppBarCommand" data-win-options="{id:'cmdAdmin', label:'Admin', section:'global' }"> </button> </div> #ENDIF 回答1: See here. There is a nuget package here to

WinJS are there #DEBUG or #RELEASE directives?

萝らか妹 提交于 2020-02-06 06:48:20
问题 I would like to exclude some code when using release vs debug. Basically I have an internal admin section for testing that I don't to ever make it into the app store by accident :) Ideally, I would just be able to do something like this: #IF DEBUG <div id="appBar" data-win-control="WinJS.UI.AppBar"> <button data-win-control="WinJS.UI.AppBarCommand" data-win-options="{id:'cmdAdmin', label:'Admin', section:'global' }"> </button> </div> #ENDIF 回答1: See here. There is a nuget package here to

WinJS are there #DEBUG or #RELEASE directives?

流过昼夜 提交于 2020-02-06 06:48:05
问题 I would like to exclude some code when using release vs debug. Basically I have an internal admin section for testing that I don't to ever make it into the app store by accident :) Ideally, I would just be able to do something like this: #IF DEBUG <div id="appBar" data-win-control="WinJS.UI.AppBar"> <button data-win-control="WinJS.UI.AppBarCommand" data-win-options="{id:'cmdAdmin', label:'Admin', section:'global' }"> </button> </div> #ENDIF 回答1: See here. There is a nuget package here to

How to encode a file from the file system as multipart/form-data?

青春壹個敷衍的年華 提交于 2020-01-24 01:14:29
问题 I want to let users upload photos to Facebook in my image viewer app. As seen in this post, Facebook Graph API - upload photo using JavaScript, I have to encode my photos as multipart/form-data to be able to upload them. How to archive this encoding on Windows.Storage.StorageFile items? 回答1: You need to open that photo (of type Windows.Storage.StorageFile ) for reading, convert it's stream to blob, append it to FormData object and upload using whatever Ajax library you want ( WinJS.xhr ,

WinJS, display image from a byte array?

穿精又带淫゛_ 提交于 2020-01-23 02:46:07
问题 I'm looking for a way to display a JPEG image stored in a byte array. This is a Windows 8 Store App built in Javascript. The byte array is returned from a C# WinRT component. Its type in C# is byte[] . Basically, what I want is to get an object so that I can call: URL.createObjectURL(bytearray, {oneTimeOnly: true}); upon. Currently this generates a runtime error because the array interface is not supported. Thanks in advance. 回答1: I discovered a far easier method. var blob = new Blob([bytes],

Chain promises and break out on error WinJS

送分小仙女□ 提交于 2020-01-16 00:59:30
问题 In WinJS, what is the correct way to chain promises if you needed to "break out" of the chain? For instance, if you had .then() functions and a final .done(). What is the correct way to return an error from a then that has others after it? Consider the following pseudo-code example function doSomething(){ return new WinJS.Promise(function(comp,err,prog){ filePicker.pickSingleFileAsync().then(function(file){ if(file){ // have a valid file return readTextAsync(File); }else{ //else user clicked

How to launch a URL in IE10 from within a Windows 8 WInJS application?

不羁的心 提交于 2020-01-13 02:57:14
问题 this might be a silly question but I have not been able to find an answer. I want to launch a specific URL with IE10 from within my Windows 8 javascript application, i.e. my application will be suspended and IE10 will launch. How do I do that with javascript? Thanks Themos 回答1: var url = new Windows.Foundation.Uri("http://www.google.com") Windows.System.Launcher.launchUriAsync(url); 来源: https://stackoverflow.com/questions/10600359/how-to-launch-a-url-in-ie10-from-within-a-windows-8-winjs