我正在创建一个应用程序,它从库中上传所选图像并将其上传到Web服务.Web服务需要所选图像的文件名以及文件内容的base64编码.我已设法通过硬编码文件路径实现此目的.但是,我正在努力获得图像的真实文件路径.我已经在网上阅读并拥有此代码,但它对我不起作用:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Uri selectedImageUri = data.getData();
String[] projection = {MediaStore.Images.Media.DATA};
try {
Cursor cursor = getContentResolver().query(selectedImageUri, projection, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(projection[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
Log.d("Picture Path", picturePath);
}
catch(Exception e) {
Log.e("Path Error", e.toString());
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
java.lang.NullPointerException
Run Code Online (Sandbox Code Playgroud)
编辑
忘了提我正在使用Kitkat.看起来我的问题与KitKat有关.我发现这个(见下文)帮助我让我的应用程序正常工作:
我有一个在Linux机器上运行的Intranet,它使用LDAP通过PHP对Windows机箱上的Active Directory进行身份验证.
我可以使用LDAP从AD检索用户的条目,并从php数组访问最后一个登录日期,例如:
echo $adAccount['lastlogontimestamp'][0]; // returns something like 129802528752492619
Run Code Online (Sandbox Code Playgroud)
如果这是一个Unix时间戳,我会使用以下PHP代码转换为人类可读日期:
date("d-m-Y H:i:s", $lastlogontimestamp);
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.有谁知道如何实现这一点,或者确实如果可以从Linux机箱中实现这一目标?
我有一个使用在LAMP系统上运行的TinyMCE编辑器的表单.我希望创建一个类似于Google文档的自动保存功能.我想到了两个场景,但两者都会在服务器上产生开销.
显然,第一点是不可行的.任何人都可以建议更好地解决第二点问题吗?
编辑1
好的,所以第三种选择可能是Thariama的回答和我的第二点的结合.
3)如果有显着变化,例如10个字符或更多,则每60秒发布一次Ajax请求
对此的任何进展都将非常感激.
编辑2
好的我已根据第3点制作了我的解决方案的原型.如果有人感兴趣,我的代码流程如下:
我正在使用JQuery.我有一个带有TinyMCE的textarea表单和一个隐藏字段来存储击键次数.
tinyMCE.init({
...
// Callback for counting keystrokes in TinyMCE
handle_event_callback : "keyCount"
});
$(function() {
autoSaveContent();
});
// Callback function - Get count, increment it and then set it
function keyCount(e) {
if(e.type == "keypress") {
var count = parseInt($("#keyCount").val());
count++;
$("#keyCount").val(count);
}
}
// Autosave every 10s if there have been over 30 keystrokes
function autoSaveContent() {
var keyCount = parseInt($("#keyCount").val());
if(keyCount > 30) {
tinyMCE.triggerSave();
var formData …Run Code Online (Sandbox Code Playgroud) 我正在开发一个Android应用程序,它将使用Moodle提供的REST Web服务core_files_upload将内容上传到我的Moodle安装中的用户的私人文件中。core_files_upload采用以下参数:
contextid
component
filearea
itemid
filepath
filename
filecontent
Run Code Online (Sandbox Code Playgroud)
Moodle Web服务的文档不是很详细,因此我将Moodle论坛和Google搜索中的内容拼凑而成,但是我觉得自己已经走到了尽头。从示例中,我看到这些参数采用以下值:
contextid: int - not sure whether this is the userid
component: "user"
filearea: "private"
itemid: 0
filepath: "/"
filename: "filename.jpg"
filecontent: base64 encoding of file
Run Code Online (Sandbox Code Playgroud)
我将我的用户ID用作上下文ID-由于缺少文档,我不确定这是否正确。当我发布这个我收到错误:
{"exception":"moodle_exception","errorcode":"nofile","message":"File not specified"}
Run Code Online (Sandbox Code Playgroud)
我查看了在“ moodle / files / externallib.php”中定义了core_files_upload的位置,当文件内容不存在时会生成此错误消息。
我尝试过发布到测试脚本,并且可以基于base64编码在Moodle服务器上成功创建图像,例如:
<?php
file_put_contents('MyFile.jpg', base64_decode($_POST['filecontent']));
Run Code Online (Sandbox Code Playgroud)
谁能阐明为什么我无法成功上传到Moodle?
contextid是执行上载的用户的userid吗?
我正在开发一个Android应用程序,它将图像从相机或设备照片库上传到远程站点.后者我工作正常,我可以选择并上传.但是,我无法拍摄完整尺寸的图片并上传.这是我的代码:
// From onCreate
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
Run Code Online (Sandbox Code Playgroud)
我有一个方法来处理Activity结果.这两个都处理从图库和相机中选择:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
String filepath = "";
Uri selectedImageUri;
if (resultCode == RESULT_OK) {
if (requestCode == CAMERA_PIC_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
// Gets real path of image so it can be uploaded
selectedImageUri = getImageUri(getApplicationContext(), photo);
}
else {
selectedImageUri = data.getData();
}
// Handle the upload ...
}
}
public Uri getImageUri(Context inContext, Bitmap inImage) {
String path …Run Code Online (Sandbox Code Playgroud) 我开发了一个必须在后台运行的控制台应用程序.应用程序必须不断检查数据库以获取新记录.如果返回新记录,则会对其进行处理.我当前使用的应用程序使用while(true)来保持应用程序运行.使用while循环是最佳解决方案.
我的代码片段:
static void Main(string[] args)
{
while(true)
{
// Query db for new records
if(record_count > 0)
{
// Process the records
}
Thread.Sleep(500);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在用 PHP 编写一个应用程序,它将连接到我域的 Google Classroom。但是,当我尝试使用 Google Classroom API 执行任何操作时出现以下错误:
Message: Error calling GET https://www.googleapis.com/v1/courses?pageSize=100: (404) Not Found
Run Code Online (Sandbox Code Playgroud)
到目前为止我的代码:
$scopes = array(
'https://www.googleapis.com/auth/classroom.courses',
'https://www.googleapis.com/auth/classroom.courses.readonly',
'https://www.googleapis.com/auth/classroom.rosters',
'https://www.googleapis.com/auth/classroom.rosters.readonly'
);
$gServiceEmail = "random@developer.gserviceaccount.com";
$gServiceKey = file_get_contents("../path/to/cert.p12");
$client = new Google_Client();
$gAuth = new Google_Auth_AssertionCredentials(
$gServiceEmail,
$scopes,
$gServiceKey
);
$gAuth->sub = "user@mydomain.com";
$client->setAssertionCredentials($gAuth);
$service = new Google_Service_Classroom($client);
$results = $service->courses->listCourses();
Run Code Online (Sandbox Code Playgroud)
我已在 Google 管理控制台的 API 设置中为服务帐户启用了范围,并在开发人员控制台中启用了 api。我哪里错了?
我正在调整Laravel 5.2中开箱即用的AuthController以满足我的需求.注册新用户时,不希望新用户自动登录.我已阅读,通过重写从AuthController的RedirectsUsers性状的postRegister方法,你可以改变工作流程.所以我的AuthController看起来像这样:
class AuthController extends Controller {
...
protected function create(array $data) {
}
public function postRegister(Request $request) {
$validator = $this->validator($request->all());
if ($validator->fails()) {
$this->throwValidationException(
$request, $validator
);
}
$this->create($request->all());
return redirect($this->redirectPath());
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我的postRegister方法似乎被忽略了.我哪里错了?