1.根据官方文档上传图片到leancloud

curl -X POST \
-H "X-LC-Id: #######" \
-H "X-LC-Key: #######" \
-H "Content-Type: image/png" \
--data-binary '@test.png' \
https://api.leancloud.cn/1.1/files/test.png1

返回信息为

{
bucket = 2qewcoP5;
createdAt = "2016-08-07T15:44:33.262Z";
name = "15.png";
objectId = 57a75761165abd00615d5d9d;
size = 9249;
url = "http://ac-2qewcoP5.clouddn.com/dYzL7RJKwci4WsDC5IKa0Ovp1yX9mImmRmMdoaKW.png";
}
===============================

这里出了问题

===============================
2.一个文件上传后关联到某个AVObject上

curl -X POST \
-H "X-LC-Id: ######" \
-H "X-LC-Key: ######" \
-H "Content-Type: application/json" \
-d '{
"name": "hjiang",
"picture": {
"id": "57a75761165abd00615d5d9d",
"__type": "File"
}
}' \
https://api.leancloud.cn/1.1/classes/Staff

=====================================

返回的信息为

{
code = 1;
error = "Object is required.";
}

====================================
这里有点不太理解,请大神指教下

你好,报错信息是 Object is required。

请贴出「2.一个文件上传后关联到某个AVObject上」这一步的代码,推测是你保存 pointer 型字段时的代码写错了。

您好,因为我想自己尝试下网络请求方面的,就都是自己写的.可能部分代码不是很规范,正在学习中.

================================================
这是我的代码
================================================

NSURL *url = [NSURL URLWithString:@"https://api.leancloud.cn/1.1/classes/Staff"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

[request setValue:@"xxxxxxxxxxxxxxxxxxxxxxxx" forHTTPHeaderField:@"X-LC-Id"];
[request setValue:@"xxxxxxxxxxxxxxxxxxxxxxxx" forHTTPHeaderField:@"X-LC-Key"];
[request setValue:@"Content-Type" forHTTPHeaderField:@"application/json"];

request.HTTPMethod = @"POST";

NSDictionary *dict = @{
    @"name": @"test111",
    @"picture": @{
        @"id": @"57c6ff80128fe1005fe90fc5",
        @"__type": @"File"
        }
    };

NSData *testData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];

request.HTTPBody = testData;

NSURLSessionTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

    if (error) {
        NSLog(@"请求出错");
    } else {
        id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
        if (error) {
            NSLog(@"解析出错");
        } else {
            NSLog(@"%@",obj);
        }
    }
    
}];

[task resume];

=========================================

请尝试把 id 这个 key 改成 objectId 试试。

你好,我测试后没有发现这个问题,以下是我的测试代码:

curl -X POST \
  -H "X-LC-Id: zhvoctxqpj9r3l9i6br8mwzc3kllryjzg1w8e4yp4ucan1nm" \
  -H "X-LC-Key: xxx" \
  -H "Content-Type: application/json" \
  -d '{
        "name": "hjiang",
        "picture": {
          "id": "56de1b80816dfa0052e648f1",
          "__type": "File"
        }
      }' \
  "https://api.leancloud.cn/1.1/classes/Staff"

请将你的完整 curl 贴出来,我们检查一下。请不要暴露 appkey。

你好,这是我的curl

===============================================
curl -X POST \
-H "X-LC-Id: 2qewcoP52UQbMqQFd5VmL03i-gzGzoHsz" \
-H "X-LC-Key: xxx" \
-H "Content-Type: application/json" \
-d '{
"name": "test111",
"picture": {
"id": "57c6ff80128fe1005fe90fc5",
"__type": "File"
}
}' \
https://api.leancloud.cn/1.1/classes/Staff1

我把 X-LC-Key 用你应用的真实 appkey 代替,执行是正常的。无法复现问题。

您好,可否让我学习下你的代码是如何实现的.或者您帮我看下,上面有我的代码,是不是哪里写的有问题.